Skip to content
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

Allow removing bottom margin from SelectControl #41269

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Enhancements

- `SelectControl`: Add `__nextHasNoMarginBottom` prop for opting into the new margin-free styles ([#41269](https://github.com/WordPress/gutenberg/pull/41269)).

### Internal

- `AlignmentMatrixControl` updated to satisfy `react/exhuastive-deps` eslint rule ([#41167](https://github.com/WordPress/gutenberg/pull/41167))
Expand Down
11 changes: 11 additions & 0 deletions packages/components/src/select-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const MySelectControl = () => {
{ label: 'Small', value: '25%' },
] }
onChange={ ( newSize ) => setSize( newSize ) }
__nextHasNoMarginBottom
/>
);
};
Expand All @@ -119,6 +120,7 @@ Render a user interface to select multiple users from a list.
{ value: 'b', label: 'User B' },
{ value: 'c', label: 'User c' },
] }
__nextHasNoMarginBottom
/>
```

Expand All @@ -133,6 +135,7 @@ const [ item, setItem ] = useState( '' );
label={ __( 'Select an item:' ) }
value={ item } // e.g: value = 'a'
onChange={ ( selection ) => { setItem( selection ) } }
__nextHasNoMarginBottom
>
<optgroup label="Theropods">
<option value="Tyrannosaurus">Tyrannosaurus</option>
Expand Down Expand Up @@ -215,6 +218,14 @@ If multiple is false the value received is a single value with the new selected
- Type: `function`
- Required: Yes

### __nextHasNoMarginBottom

Start opting into the new margin-free styles that will become the default in a future version.

- Type: `Boolean`
- Required: No
- Default: `false`

## Related components

- To select one option from a set, and you want to show them all the available options at once, use the `Radio` component.
Expand Down
7 changes: 6 additions & 1 deletion packages/components/src/select-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function UnforwardedSelectControl(
children,
prefix,
suffix,
__nextHasNoMarginBottom = false,
...props
}: WordPressComponentProps< SelectControlProps, 'select', false >,
ref: ForwardedRef< HTMLSelectElement >
Expand Down Expand Up @@ -85,7 +86,11 @@ function UnforwardedSelectControl(

/* eslint-disable jsx-a11y/no-onchange */
return (
<BaseControl help={ help } id={ id }>
<BaseControl
help={ help }
id={ id }
__nextHasNoMarginBottom={ __nextHasNoMarginBottom }
>
<InputBase
className={ classes }
disabled={ disabled }
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/select-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface SelectControlProps
| 'size'
| 'suffix'
>,
Pick< BaseControlProps, 'help' > {
Pick< BaseControlProps, 'help' | '__nextHasNoMarginBottom' > {
/**
* If this property is added, multiple values can be selected. The value passed should be an array.
*
Expand Down