-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add margin-bottom lint rules for BaseControl #64355
Changes from all commits
a7beddd
aa333d5
4ea9b9f
9771ed8
58d1297
78bbf67
fd1a731
85f7e92
aec5c2d
55ede85
f12b7fd
a9e31ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -28,7 +28,7 @@ import { | |||||
ToolbarButton, | ||||||
ResizableBox, | ||||||
PanelBody, | ||||||
BaseControl, | ||||||
__experimentalVStack as VStack, | ||||||
__experimentalUseCustomUnits as useCustomUnits, | ||||||
__experimentalUnitControl as UnitControl, | ||||||
} from '@wordpress/components'; | ||||||
|
@@ -408,12 +408,14 @@ export default function SearchEdit( { | |||||
|
||||||
<InspectorControls> | ||||||
<PanelBody title={ __( 'Settings' ) }> | ||||||
<BaseControl | ||||||
label={ __( 'Width' ) } | ||||||
id={ unitControlInputId } | ||||||
<VStack | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Testing instructionsIn the editor, add a Search block and see the block inspector.
This UI probably should be updated to Spacing is the same as a similar pattern in the Latest Posts block. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good, but it would have been suitable for another PR, perhaps with a design person taking a look 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may be right! This is still bad though, just incrementally better. I'm keeping an eye on #52223 to figure out what this UI should be ideally. |
||||||
className="wp-block-search__inspector-controls" | ||||||
spacing={ 4 } | ||||||
> | ||||||
<UnitControl | ||||||
id={ unitControlInputId } | ||||||
__next40pxDefaultSize | ||||||
label={ __( 'Width' ) } | ||||||
id={ unitControlInputId } // unused, kept for backwards compatibility | ||||||
min={ | ||||||
isPercentageUnit( widthUnit ) ? 0 : MIN_WIDTH | ||||||
} | ||||||
|
@@ -427,7 +429,6 @@ export default function SearchEdit( { | |||||
parseInt( newWidth, 10 ) > 100 | ||||||
? 100 | ||||||
: newWidth; | ||||||
|
||||||
setAttributes( { | ||||||
width: parseInt( filteredWidth, 10 ), | ||||||
} ); | ||||||
|
@@ -445,9 +446,8 @@ export default function SearchEdit( { | |||||
value={ `${ width }${ widthUnit }` } | ||||||
units={ units } | ||||||
/> | ||||||
|
||||||
<ButtonGroup | ||||||
className="wp-block-search__components-button-group" | ||||||
className="wp-block-search__components-button-group" // unused, kept for backwards compatibility | ||||||
aria-label={ __( 'Percentage Width' ) } | ||||||
> | ||||||
{ [ 25, 50, 75, 100 ].map( ( widthValue ) => { | ||||||
|
@@ -473,7 +473,7 @@ export default function SearchEdit( { | |||||
); | ||||||
} ) } | ||||||
</ButtonGroup> | ||||||
</BaseControl> | ||||||
</VStack> | ||||||
</PanelBody> | ||||||
</InspectorControls> | ||||||
</> | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,8 @@ import { | |
__experimentalUnitControl as UnitControl, | ||
__experimentalUseCustomUnits as useCustomUnits, | ||
__experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue, | ||
__experimentalVStack as VStack, | ||
Disabled, | ||
BaseControl, | ||
} from '@wordpress/components'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
@@ -110,17 +110,20 @@ function TagCloudEdit( { attributes, setAttributes } ) { | |
const inspectorControls = ( | ||
<InspectorControls> | ||
<PanelBody title={ __( 'Settings' ) }> | ||
<SelectControl | ||
__nextHasNoMarginBottom | ||
__next40pxDefaultSize | ||
label={ __( 'Taxonomy' ) } | ||
options={ getTaxonomyOptions() } | ||
value={ taxonomy } | ||
onChange={ ( selectedTaxonomy ) => | ||
setAttributes( { taxonomy: selectedTaxonomy } ) | ||
} | ||
/> | ||
<BaseControl> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
<VStack | ||
spacing={ 4 } | ||
className="wp-block-tag-cloud__inspector-settings" | ||
> | ||
<SelectControl | ||
__nextHasNoMarginBottom | ||
__next40pxDefaultSize | ||
label={ __( 'Taxonomy' ) } | ||
options={ getTaxonomyOptions() } | ||
value={ taxonomy } | ||
onChange={ ( selectedTaxonomy ) => | ||
setAttributes( { taxonomy: selectedTaxonomy } ) | ||
} | ||
/> | ||
<Flex gap={ 4 }> | ||
<FlexItem isBlock> | ||
<UnitControl | ||
|
@@ -155,27 +158,27 @@ function TagCloudEdit( { attributes, setAttributes } ) { | |
/> | ||
</FlexItem> | ||
</Flex> | ||
</BaseControl> | ||
<RangeControl | ||
__nextHasNoMarginBottom | ||
__next40pxDefaultSize | ||
label={ __( 'Number of tags' ) } | ||
value={ numberOfTags } | ||
onChange={ ( value ) => | ||
setAttributes( { numberOfTags: value } ) | ||
} | ||
min={ MIN_TAGS } | ||
max={ MAX_TAGS } | ||
required | ||
/> | ||
<ToggleControl | ||
__nextHasNoMarginBottom | ||
label={ __( 'Show tag counts' ) } | ||
checked={ showTagCounts } | ||
onChange={ () => | ||
setAttributes( { showTagCounts: ! showTagCounts } ) | ||
} | ||
/> | ||
<RangeControl | ||
__nextHasNoMarginBottom | ||
__next40pxDefaultSize | ||
label={ __( 'Number of tags' ) } | ||
value={ numberOfTags } | ||
onChange={ ( value ) => | ||
setAttributes( { numberOfTags: value } ) | ||
} | ||
min={ MIN_TAGS } | ||
max={ MAX_TAGS } | ||
required | ||
/> | ||
<ToggleControl | ||
__nextHasNoMarginBottom | ||
label={ __( 'Show tag counts' ) } | ||
checked={ showTagCounts } | ||
onChange={ () => | ||
setAttributes( { showTagCounts: ! showTagCounts } ) | ||
} | ||
/> | ||
</VStack> | ||
</PanelBody> | ||
</InspectorControls> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,11 @@ | |
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
.wp-block-tag-cloud__inspector-settings { | ||
.components-base-control, | ||
.components-base-control:last-child { | ||
// Cancel out extra margins added by block inspector | ||
margin-bottom: 0; | ||
} | ||
} | ||
Comment on lines
+11
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So painful 😭 I'm going to propose a better way to deal with these once the deprecation work is done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed. Let's definitely open an issue to keep track of those 👍 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,7 @@ const VideoSettings = ( { setAttributes, attributes } ) => { | |
) } | ||
/> | ||
<SelectControl | ||
__next40pxDefaultSize | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the "Preload" dropdown in the Video block inspector controls. (It's named like it's a reused component, but currently only used in the Video block.) |
||
__nextHasNoMarginBottom | ||
label={ __( 'Preload' ) } | ||
value={ preload } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -219,7 +219,7 @@ function VideoEdit( { | |
attributes={ attributes } | ||
/> | ||
<MediaUploadCheck> | ||
<BaseControl className="editor-video-poster-control"> | ||
<div className="editor-video-poster-control"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
<BaseControl.VisualLabel> | ||
{ __( 'Poster image' ) } | ||
</BaseControl.VisualLabel> | ||
|
@@ -265,7 +265,7 @@ function VideoEdit( { | |
{ __( 'Remove' ) } | ||
</Button> | ||
) } | ||
</BaseControl> | ||
</div> | ||
</MediaUploadCheck> | ||
</PanelBody> | ||
</InspectorControls> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,29 +26,6 @@ import { contextConnectWithoutRef, useContextSystem } from '../context'; | |
|
||
export { useBaseControlProps } from './hooks'; | ||
|
||
/** | ||
* `BaseControl` is a component used to generate labels and help text for components handling user inputs. | ||
* | ||
* ```jsx | ||
* import { BaseControl, useBaseControlProps } from '@wordpress/components'; | ||
* | ||
* // Render a `BaseControl` for a textarea input | ||
* const MyCustomTextareaControl = ({ children, ...baseProps }) => ( | ||
* // `useBaseControlProps` is a convenience hook to get the props for the `BaseControl` | ||
* // and the inner control itself. Namely, it takes care of generating a unique `id`, | ||
* // properly associating it with the `label` and `help` elements. | ||
* const { baseControlProps, controlProps } = useBaseControlProps( baseProps ); | ||
* | ||
* return ( | ||
* <BaseControl { ...baseControlProps } __nextHasNoMarginBottom={ true }> | ||
* <textarea { ...controlProps }> | ||
* { children } | ||
* </textarea> | ||
* </BaseControl> | ||
* ); | ||
* ); | ||
* ``` | ||
*/ | ||
const UnconnectedBaseControl = ( | ||
props: WordPressComponentProps< BaseControlProps, null > | ||
) => { | ||
|
@@ -105,23 +82,6 @@ const UnconnectedBaseControl = ( | |
); | ||
}; | ||
|
||
/** | ||
* `BaseControl.VisualLabel` is used to render a purely visual label inside a `BaseControl` component. | ||
* | ||
* It should only be used in cases where the children being rendered inside `BaseControl` are already accessibly labeled, | ||
* e.g., a button, but we want an additional visual label for that section equivalent to the labels `BaseControl` would | ||
* otherwise use if the `label` prop was passed. | ||
* | ||
* @example | ||
* import { BaseControl } from '@wordpress/components'; | ||
* | ||
* const MyBaseControl = () => ( | ||
* <BaseControl help="This button is already accessibly labeled."> | ||
* <BaseControl.VisualLabel>Author</BaseControl.VisualLabel> | ||
* <Button>Select an author</Button> | ||
* </BaseControl> | ||
* ); | ||
*/ | ||
const UnforwardedVisualLabel = ( | ||
props: WordPressComponentProps< BaseControlVisualLabelProps, 'span' >, | ||
ref: ForwardedRef< any > | ||
|
@@ -141,9 +101,56 @@ const UnforwardedVisualLabel = ( | |
|
||
export const VisualLabel = forwardRef( UnforwardedVisualLabel ); | ||
|
||
/** | ||
* `BaseControl` is a component used to generate labels and help text for components handling user inputs. | ||
* | ||
Comment on lines
+104
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved the JSDocs so they are correctly associated with the exported components. Also made sure the code snippets both have the no margin prop. |
||
* ```jsx | ||
* import { BaseControl, useBaseControlProps } from '@wordpress/components'; | ||
* | ||
* // Render a `BaseControl` for a textarea input | ||
* const MyCustomTextareaControl = ({ children, ...baseProps }) => ( | ||
* // `useBaseControlProps` is a convenience hook to get the props for the `BaseControl` | ||
* // and the inner control itself. Namely, it takes care of generating a unique `id`, | ||
* // properly associating it with the `label` and `help` elements. | ||
* const { baseControlProps, controlProps } = useBaseControlProps( baseProps ); | ||
* | ||
* return ( | ||
* <BaseControl { ...baseControlProps } __nextHasNoMarginBottom> | ||
* <textarea { ...controlProps }> | ||
* { children } | ||
* </textarea> | ||
* </BaseControl> | ||
* ); | ||
* ); | ||
* ``` | ||
*/ | ||
export const BaseControl = Object.assign( | ||
contextConnectWithoutRef( UnconnectedBaseControl, 'BaseControl' ), | ||
{ VisualLabel } | ||
|
||
{ | ||
/** | ||
* `BaseControl.VisualLabel` is used to render a purely visual label inside a `BaseControl` component. | ||
* | ||
* It should only be used in cases where the children being rendered inside `BaseControl` are already accessibly labeled, | ||
* e.g., a button, but we want an additional visual label for that section equivalent to the labels `BaseControl` would | ||
* otherwise use if the `label` prop was passed. | ||
* | ||
* ```jsx | ||
* import { BaseControl } from '@wordpress/components'; | ||
* | ||
* const MyBaseControl = () => ( | ||
* <BaseControl | ||
* __nextHasNoMarginBottom | ||
* help="This button is already accessibly labeled." | ||
* > | ||
* <BaseControl.VisualLabel>Author</BaseControl.VisualLabel> | ||
* <Button>Select an author</Button> | ||
* </BaseControl> | ||
* ); | ||
* ``` | ||
*/ | ||
VisualLabel, | ||
} | ||
); | ||
|
||
export default BaseControl; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -20,7 +20,11 @@ import { | |||||
|
||||||
const DEFAULT_UNITS = [ 'px', 'em', 'rem', 'vw', 'vh' ]; | ||||||
|
||||||
function SizeControl( props ) { | ||||||
function SizeControl( { | ||||||
// Do not allow manipulation of margin bottom | ||||||
__nextHasNoMarginBottom, | ||||||
Comment on lines
+24
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No back compat concerns because this component is private. |
||||||
...props | ||||||
} ) { | ||||||
const { baseControlProps } = useBaseControlProps( props ); | ||||||
const { value, onChange, fallbackValue, disabled } = props; | ||||||
|
||||||
|
@@ -45,7 +49,7 @@ function SizeControl( props ) { | |||||
}; | ||||||
|
||||||
return ( | ||||||
<BaseControl { ...baseControlProps }> | ||||||
<BaseControl { ...baseControlProps } __nextHasNoMarginBottom> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Testing instructionsIn Global Styles, go to Typography ▸ Font size presets ▸ (whatever option). Enable the Fluid typography and Custom fluid values toggles.
I normalized the spacing. I extracted out a labeling bug as a separate issue: #64406. |
||||||
<Flex> | ||||||
<FlexItem isBlock> | ||||||
<UnitControl | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -323,6 +323,7 @@ function PushChangesToGlobalStylesControl( { | |
|
||
return ( | ||
<BaseControl | ||
__nextHasNoMarginBottom | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
className="edit-site-push-changes-to-global-styles-control" | ||
help={ sprintf( | ||
// translators: %s: Title of the block e.g. 'Heading'. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,6 +143,7 @@ export function CreateTemplatePartModalContents( { | |
required | ||
/> | ||
<BaseControl | ||
__nextHasNoMarginBottom | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
label={ __( 'Area' ) } | ||
id={ `editor-create-template-part-modal__area-selection-${ instanceId }` } | ||
className="editor-create-template-part-modal__area-base-control" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,7 @@ function PatternOverridesControls( { | |
<> | ||
<InspectorControls group="advanced"> | ||
<BaseControl | ||
__nextHasNoMarginBottom | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
id={ controlId } | ||
label={ __( 'Overrides' ) } | ||
help={ helpText } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing instructions
Somewhere in this file, set the
imageSizeOptions
variable asfalse
. In the editor, add a Gallery block with an image, and see the block inspector.