Skip to content

Commit

Permalink
Add margin-bottom lint rules for TextControl (#64212)
Browse files Browse the repository at this point in the history
* Fix in Form block

* Fix in DataForm

* Fix in Add new post modal

* Fix in Language format popover

* Add lint rule

Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
  • Loading branch information
3 people authored Aug 5, 2024
1 parent e3c2cd3 commit f6c809f
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 24 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ module.exports = {
'FocalPointPicker',
'RangeControl',
'SearchControl',
'TextControl',
'TextareaControl',
'ToggleGroupControl',
'TreeSelect',
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/form-input/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function InputFieldBlock( { attributes, setAttributes, className } ) {
) }
<InspectorControls group="advanced">
<TextControl
__nextHasNoMarginBottom
autoComplete="off"
label={ __( 'Name' ) }
value={ name }
Expand Down
25 changes: 15 additions & 10 deletions packages/dataviews/src/components/dataform/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { Dispatch, SetStateAction } from 'react';
/**
* WordPress dependencies
*/
import { __experimentalVStack as VStack } from '@wordpress/components';
import { useMemo } from '@wordpress/element';

/**
Expand Down Expand Up @@ -37,14 +38,18 @@ export default function DataForm< Item >( {
[ fields, form.visibleFields ]
);

return visibleFields.map( ( field ) => {
return (
<field.Edit
key={ field.id }
data={ data }
field={ field }
onChange={ onChange }
/>
);
} );
return (
<VStack spacing={ 4 }>
{ visibleFields.map( ( field ) => {
return (
<field.Edit
key={ field.id }
data={ data }
field={ field }
onChange={ onChange }
/>
);
} ) }
</VStack>
);
}
2 changes: 2 additions & 0 deletions packages/dataviews/src/field-types/integer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ function Edit< Item >( {
value={ value }
options={ elements }
onChange={ onChangeControl }
__next40pxDefaultSize
__nextHasNoMarginBottom
/>
);
}
Expand Down
1 change: 1 addition & 0 deletions packages/dataviews/src/field-types/text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ function Edit< Item >( {
value={ value ?? '' }
onChange={ onChangeControl }
__next40pxDefaultSize
__nextHasNoMarginBottom
/>
);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/edit-site/src/components/add-new-post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ export default function AddNewPostModal( { postType, onSave, onClose } ) {
size="small"
>
<form onSubmit={ createPost }>
<VStack spacing={ 3 }>
<VStack spacing={ 4 }>
<TextControl
__next40pxDefaultSize
__nextHasNoMarginBottom
label={ __( 'Title' ) }
onChange={ setTitle }
placeholder={ __( 'No title' ) }
Expand Down
29 changes: 18 additions & 11 deletions packages/edit-site/src/components/post-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import { __ } from '@wordpress/i18n';
import { DataForm, isItemValid } from '@wordpress/dataviews';
import { useDispatch, useSelect, useRegistry } from '@wordpress/data';
import { store as coreDataStore } from '@wordpress/core-data';
import { Button } from '@wordpress/components';
import {
Button,
FlexItem,
__experimentalVStack as VStack,
} from '@wordpress/components';
import { useState, useMemo } from '@wordpress/element';

/**
Expand Down Expand Up @@ -71,22 +75,25 @@ function PostEditForm( { postType, postId } ) {

const isUpdateDisabled = ! isItemValid( itemWithEdits, fields, form );
return (
<form onSubmit={ onSubmit }>
<VStack as="form" onSubmit={ onSubmit } spacing={ 4 }>
<DataForm
data={ itemWithEdits }
fields={ fields }
form={ form }
onChange={ setEdits }
/>
<Button
variant="primary"
type="submit"
accessibleWhenDisabled
disabled={ isUpdateDisabled }
>
{ __( 'Update' ) }
</Button>
</form>
<FlexItem>
<Button
variant="primary"
type="submit"
accessibleWhenDisabled
disabled={ isUpdateDisabled }
__next40pxDefaultSize
>
{ __( 'Update' ) }
</Button>
</FlexItem>
</VStack>
);
}

Expand Down
12 changes: 10 additions & 2 deletions packages/format-library/src/language/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
Button,
Popover,
__experimentalHStack as HStack,
__experimentalVStack as VStack,
} from '@wordpress/components';
import { useState } from '@wordpress/element';
import { applyFormat, removeFormat, useAnchor } from '@wordpress/rich-text';
Expand Down Expand Up @@ -78,7 +79,9 @@ function InlineLanguageUI( { value, contentRef, onChange, onClose } ) {
anchor={ popoverAnchor }
onClose={ onClose }
>
<form
<VStack
as="form"
spacing={ 4 }
className="block-editor-format-toolbar__language-container-content"
onSubmit={ ( event ) => {
event.preventDefault();
Expand All @@ -95,6 +98,8 @@ function InlineLanguageUI( { value, contentRef, onChange, onClose } ) {
} }
>
<TextControl
__next40pxDefaultSize
__nextHasNoMarginBottom
label={ title }
value={ lang }
onChange={ ( val ) => setLang( val ) }
Expand All @@ -103,6 +108,8 @@ function InlineLanguageUI( { value, contentRef, onChange, onClose } ) {
) }
/>
<SelectControl
__next40pxDefaultSize
__nextHasNoMarginBottom
label={ __( 'Text direction' ) }
value={ dir }
options={ [
Expand All @@ -119,12 +126,13 @@ function InlineLanguageUI( { value, contentRef, onChange, onClose } ) {
/>
<HStack alignment="right">
<Button
__next40pxDefaultSize
variant="primary"
type="submit"
text={ __( 'Apply' ) }
/>
</HStack>
</form>
</VStack>
</Popover>
);
}

0 comments on commit f6c809f

Please sign in to comment.