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

feat(dropdown): fix the single/multiple selection controlled handling #1814

Merged
merged 3 commits into from
Jan 16, 2024
Merged
Changes from all 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
10 changes: 7 additions & 3 deletions packages/components/dropdown/src/useDropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface DownshiftProps {
}

/**
* This hooks abstract the complexity of using downshift with both single and multiple selection.
* This hook abstract the complexity of using downshift with both single and multiple selection.
*/
export const useDropdown = ({
itemsMap,
Expand All @@ -36,10 +36,14 @@ export const useDropdown = ({

const downshiftMultipleSelection = useMultipleSelection<DropdownItem>({
selectedItems: value
? items.filter(item => (value as string[]).includes(item.value))
? items.filter(item =>
multiple ? (value as string[]).includes(item.value) : value === item.value
)
: undefined,
initialSelectedItems: defaultValue
? items.filter(item => (defaultValue as string[]).includes(item.value))
? items.filter(item =>
multiple ? (defaultValue as string[]).includes(item.value) : defaultValue === item.value
)
: undefined,

onSelectedItemsChange: ({ selectedItems }) => {
Expand Down
Loading