-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(multiselect combobox): expose state hook / inversion of control (#…
…3470) * feat(multiselect-combobox): add state hook functionality * chore: minor improvement to the dropdown open orientation * docs(multiselect-combobox): fix link to hook * fix: changesets message
- Loading branch information
Showing
12 changed files
with
342 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@twilio-paste/combobox': minor | ||
'@twilio-paste/core': minor | ||
--- | ||
|
||
[MultiSelect Combobox] allow inversion of control with the internal state so that consumers can manage the selectedItems array themselves. This enables functionality like clearing the selectedItems through an external Button. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/paste-core/components/combobox/src/multiselect/extractPropsFromState.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {useMultiSelectPrimitive} from '@twilio-paste/combobox-primitive'; | ||
import type {UseMultiSelectPrimitiveReturnValue} from '@twilio-paste/combobox-primitive'; | ||
import isEmpty from 'lodash/isEmpty'; | ||
|
||
import type {Item, MultiselectComboboxProps} from '../types'; | ||
|
||
interface DefaultStateProps { | ||
initialSelectedItems: MultiselectComboboxProps['initialSelectedItems']; | ||
onSelectedItemsChange: MultiselectComboboxProps['onSelectedItemsChange']; | ||
state: MultiselectComboboxProps['state']; | ||
} | ||
|
||
export const extractPropsFromState = ({ | ||
state, | ||
initialSelectedItems, | ||
onSelectedItemsChange, | ||
}: DefaultStateProps): UseMultiSelectPrimitiveReturnValue<Item> => { | ||
// If they're providing their own state management, we don't need to do anything | ||
if (state != null && !isEmpty(state)) { | ||
return state; | ||
} | ||
|
||
// Otherwise, we'll use our own state management | ||
return useMultiSelectPrimitive<Item>({ | ||
initialSelectedItems, | ||
onSelectedItemsChange, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.