Skip to content

Commit

Permalink
ComboboxControl: Add flag to remove bottom margin (#43165)
Browse files Browse the repository at this point in the history
* ComboboxControl: Add flag to remove bottom margin

* Use Action for value inspection in story

* Add changelog

* Add optional chaining for onChange

Co-authored-by: Marco Ciampini <[email protected]>

Co-authored-by: Marco Ciampini <[email protected]>
  • Loading branch information
mirka and ciampo authored Aug 16, 2022
1 parent 1cd4c46 commit 430a9c0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
- `BoxControl`: Export `applyValueToSides` util function. ([#42733](https://github.com/WordPress/gutenberg/pull/42733/)).
- `ColorPalette`: use index while iterating over color entries to avoid React "duplicated key" warning ([#43096](https://github.com/WordPress/gutenberg/pull/43096)).
- `AnglePickerControl`: Add `__nextHasNoMarginBottom` prop for opting into the new margin-free styles ([#43160](https://github.com/WordPress/gutenberg/pull/43160/)).
- `ComboboxControl`: Add `__nextHasNoMarginBottom` prop for opting into the new margin-free styles ([#43165](https://github.com/WordPress/gutenberg/pull/43165/)).

### Internal

Expand Down
3 changes: 3 additions & 0 deletions packages/components/src/combobox-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const DetectOutside = withFocusOutside(
);

function ComboboxControl( {
/** Start opting into the new margin-free styles that will become the default in a future version. */
__nextHasNoMarginBottom = false,
__next36pxDefaultSize,
value: valueProp,
label,
Expand Down Expand Up @@ -220,6 +222,7 @@ function ComboboxControl( {
return (
<DetectOutside onFocusOutside={ onFocusOutside }>
<BaseControl
__nextHasNoMarginBottom={ __nextHasNoMarginBottom }
className={ classnames(
className,
'components-combobox-control'
Expand Down
12 changes: 9 additions & 3 deletions packages/components/src/combobox-control/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ const countries = [
export default {
title: 'Components/ComboboxControl',
component: ComboboxControl,
argTypes: {
__nextHasNoMarginBottom: { control: { type: 'boolean' } },
onChange: { action: 'onChange' },
},
};

const mapCountryOption = ( country ) => ( {
Expand All @@ -266,17 +270,19 @@ const mapCountryOption = ( country ) => ( {

const countryOptions = countries.map( mapCountryOption );

function Template( args ) {
function Template( { onChange, ...args } ) {
const [ value, setValue ] = useState( null );

return (
<>
<ComboboxControl
{ ...args }
value={ value }
onChange={ setValue }
onChange={ ( ...changeArgs ) => {
setValue( ...changeArgs );
onChange?.( ...changeArgs );
} }
/>
<p>Value: { value }</p>
</>
);
}
Expand Down
1 change: 0 additions & 1 deletion packages/components/src/combobox-control/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ input.components-combobox-control__input[type="text"] {
flex-wrap: wrap;
align-items: flex-start;
width: 100%;
margin: 0 0 $grid-unit-10 0;
padding: 0;

&:focus-within {
Expand Down

0 comments on commit 430a9c0

Please sign in to comment.