Skip to content

Commit

Permalink
fix: clear value in single select control (#62)
Browse files Browse the repository at this point in the history
Co-authored-by: santiago.trigo <[email protected]>
  • Loading branch information
trigoporres and santiago.trigo authored Jul 8, 2024
1 parent 8816a07 commit 99e0c5b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,33 @@ export const SingleOption: Story = {
})(args),
};

export const SingleOptionWithReset: Story = {
name: 'Single selection with reset',
render: (args) =>
((props) => {
const [value, setValue] = React.useState<SelectControlProps['value']>();
return (
<>
<SelectControl
{...props}
//menuIsOpen
onChange={(opt: TSelectOption) => {
setValue(opt.value)
}}
options={[
{ value: 1, label: 'Option one' },
{ value: 2, label: 'Option two' },
{ value: 3, label: 'Option three' },
{ value: 4, label: 'Option four' },
]}
value={value}
/>
<button onClick={() => setValue(undefined)}>RESET</button>
</>
);
})(args),
};

export const SingleOptionWithIcons: Story = {
name: 'Single selection with option/value icons',
render: (args) =>
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/components/SelectControl/SelectControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ export const SelectControl = <
defaultStyles as StylesConfig,
componentStyles,
)}
{...(value && {
value: findValue(value as TSelectOption, rest.options, rest.isMulti),
})}
value={findValue(value as TSelectOption, rest.options, rest.isMulti)}
components={
{ ...defaultComponents, ...components } as Partial<
SelectComponents<Option, IsMulti, Group>
Expand Down

0 comments on commit 99e0c5b

Please sign in to comment.