Skip to content

Commit

Permalink
Components: Set a default for the ComboboxControl onFilterValueChange (
Browse files Browse the repository at this point in the history
…#28492)

* Make the onFieldValueChange prop optional by setting a default.

* Update the Storybook example.

* Swap to using lodash's noop
  • Loading branch information
pablinos authored Feb 10, 2021
1 parent dd6c72e commit 9a5fef7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/components/src/combobox-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import classnames from 'classnames';
import { deburr } from 'lodash';
import { noop, deburr } from 'lodash';
/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -46,7 +46,7 @@ function ComboboxControl( {
label,
options,
onChange,
onFilterValueChange,
onFilterValueChange = noop,
hideLabelFromVision,
help,
allowReset = true,
Expand Down
23 changes: 10 additions & 13 deletions packages/components/src/combobox-control/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,14 @@ export default {
component: ComboboxControl,
};

function ComboboxControlWithState() {
const mapCountryOption = ( country ) => ( {
value: country.code,
label: country.name,
} );
const [ filteredOptions, setFilteredOptions ] = useState(
countries.map( mapCountryOption )
);
const mapCountryOption = ( country ) => ( {
value: country.code,
label: country.name,
} );

const countryOptions = countries.map( mapCountryOption );

function CountryCodeComboboxControl() {
const [ value, setValue ] = useState( null );

return (
Expand All @@ -275,13 +275,10 @@ function ComboboxControlWithState() {
value={ value }
onChange={ setValue }
label="Select a country"
options={ filteredOptions }
onFilterValueChange={ () =>
setFilteredOptions( countries.map( mapCountryOption ) )
}
options={ countryOptions }
/>
<p>Value: { value }</p>
</>
);
}
export const _default = () => <ComboboxControlWithState />;
export const _default = () => <CountryCodeComboboxControl />;

0 comments on commit 9a5fef7

Please sign in to comment.