You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add controllable selectedIds and unselectedIds to the useSelectionListModel. A common ask is for control over a <Select> component's selected state. A "controllable" model is one where the model handles internal state changes based on use input, but allows state to be overridden by incoming config, hence allowing control externally.
We can add the following to the defaultConfig in the useSelectionListModel:
This will allow an override of the model.state.selectedIds from externally:
const[selectedIds,setSelectedIds]=React.useState<string[]>([]);constmodel=useSelectModel({items: options,
selectedIds,onSelect({ id }){setSelectedIds([id])}})// some button callback or server fetch callback or somethingsetSelectedIds(['Foo'])
Motivation
Right now, a developer needs to use a key to completely throw away a component in order to update the current selected state.
馃殌 Feature Proposal
Add controllable
selectedIds
andunselectedIds
to theuseSelectionListModel
. A common ask is for control over a<Select>
component's selected state. A "controllable" model is one where the model handles internal state changes based on use input, but allows state to be overridden by incoming config, hence allowing control externally.We can add the following to the
defaultConfig
in theuseSelectionListModel
:Then update the
state
to:This will allow an override of the
model.state.selectedIds
from externally:Motivation
Right now, a developer needs to use a
key
to completely throw away a component in order to update the current selected state.Example
https://stackblitz.com/edit/controllable-select-model-6bwrh3?file=src%2FuseControlledSelectModel.ts,src%2FApp.tsx
The text was updated successfully, but these errors were encountered: