Skip to content

Commit

Permalink
Feat: Added closeOnChangedValue functionality. (#555)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdokimakis authored Feb 16, 2022
1 parent 536d979 commit 820f748
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ More examples can be found [here ↗](https://react-multi-select-component.pages
| `ClearSelectedIcon` | Custom Clear Icon for Selected Items | `ReactNode` | |
| `isCreatable` | Allows user to create unavailable option(s) [example ↗](https://react-multi-select-component.pages.dev/?path=/story/creatable--creatable-default) | `boolean` | `false` |
| `onCreateOption` | allows to override newly created option [example ↗](https://react-multi-select-component.pages.dev/?path=/story/creatable--creatable-custom) | `function` | |
| `closeOnChangedValue` | automatically closes dropdown when its value is changed | `boolean` | `false` |

## 📝 Changelog

Expand Down
1 change: 1 addition & 0 deletions src/lib/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ export interface ISelectProps {
isOpen?: boolean;
isCreatable?: boolean;
onCreateOption?;
closeOnChangedValue?: boolean;
}
7 changes: 7 additions & 0 deletions src/multi-select/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ const Dropdown = () => {
isOpen,
defaultIsOpen,
ClearSelectedIcon,
closeOnChangedValue
} = useMultiSelect();

useEffect(() => {
if (closeOnChangedValue) {
setExpanded(false)
}
}, [value])

const [isInternalExpand, setIsInternalExpand] = useState(true);
const [expanded, setExpanded] = useState(defaultIsOpen);
const [hasFocus, setHasFocus] = useState(false);
Expand Down

0 comments on commit 820f748

Please sign in to comment.