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

SelectControl: Add onChange, onBlur and onFocus to storybook actions #45432

Merged
merged 4 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
- `CustomGradientBar`: Refactor away from Lodash ([#45367](https://github.com/WordPress/gutenberg/pull/45367/)).
- `TextControl`: Set Storybook control types on `help`, `label` and `type` ([#45405](https://github.com/WordPress/gutenberg/pull/45405)).
- `Autocomplete`: use Popover's new `placement` prop instead of legacy `position` prop ([#44396](https://github.com/WordPress/gutenberg/pull/44396/)).
- `SelectControl`: Add `onChange` to storybook actions ([#45432](https://github.com/WordPress/gutenberg/pull/45432/)).

## 21.3.0 (2022-10-19)

Expand Down
13 changes: 9 additions & 4 deletions packages/components/src/select-control/stories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const meta: ComponentMeta< typeof SelectControl > = {
prefix: { control: { type: 'text' } },
suffix: { control: { type: 'text' } },
value: { control: { type: null } },
onChange: { action: 'onChange' },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative that we could look into adopting across the package is to use a regex to mark as actions all on* props (see for example FocalPointPicker's Storybook parameters)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Didn't know you could do that. Would be great to get onBlur and onFocus as well. I'll update the PR later today.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the PR to match all on* using regex.

},
parameters: {
controls: { expanded: true },
Expand All @@ -31,17 +32,21 @@ const meta: ComponentMeta< typeof SelectControl > = {
};
export default meta;

const SelectControlWithState: ComponentStory< typeof SelectControl > = (
args
) => {
const SelectControlWithState: ComponentStory< typeof SelectControl > = ( {
onChange,
...args
} ) => {
const [ selection, setSelection ] =
useState< ComponentProps< typeof SelectControl >[ 'value' ] >();

return (
<SelectControl
{ ...args }
value={ selection }
onChange={ setSelection }
onChange={ ( value ) => {
setSelection( value );
onChange?.( value );
} }
/>
);
};
Expand Down