Skip to content

Commit 3887a59

Browse files
committed
Controls: Allow resetting the Select control
1 parent de619c1 commit 3887a59

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

code/addons/docs/src/blocks/controls/options/Select.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ const SingleSelect: FC<SelectProps> = ({ name, value, options, onChange, argType
120120
{name}
121121
</label>
122122
<OptionsSelect disabled={readonly} id={controlId} value={selection} onChange={handleChange}>
123-
<option key="no-selection" disabled>
123+
<option disabled={selection === NO_SELECTION} key="no-selection">
124124
{NO_SELECTION}
125125
</option>
126126
{Object.keys(options).map((key) => (

code/addons/docs/src/blocks/controls/options/SelectOptions.stories.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Meta, StoryObj } from '@storybook/react-vite';
22

3-
import { fn } from 'storybook/test';
3+
import { expect, fn, userEvent } from 'storybook/test';
44

55
import { OptionsControl } from './Options';
66

@@ -70,6 +70,28 @@ export const ArrayUndefined: Story = {
7070
},
7171
};
7272

73+
export const ArrayResettable: Story = {
74+
args: {
75+
value: undefined,
76+
},
77+
play: async ({ canvas, args }) => {
78+
const select = canvas.getByRole('combobox');
79+
expect(select).toHaveValue('Choose option...');
80+
81+
await userEvent.click(select);
82+
await userEvent.selectOptions(select, arrayOptions[2]);
83+
84+
expect(args.onChange).toHaveBeenCalledWith(arrayOptions[2]);
85+
expect(select).toHaveValue(arrayOptions[2]);
86+
87+
await userEvent.click(select);
88+
await userEvent.selectOptions(select, 'Choose option...');
89+
90+
expect(args.onChange).toHaveBeenCalledWith(undefined);
91+
expect(select).toHaveValue('Choose option...');
92+
},
93+
};
94+
7395
export const ArrayMultiUndefined: Story = {
7496
args: {
7597
type: 'multi-select',

0 commit comments

Comments
 (0)