-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: accept readonly array for multiple select value #9221
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
base: main
Are you sure you want to change the base?
Conversation
| export type SelectionMode = 'single' | 'multiple'; | ||
| export type ValueType<M extends SelectionMode> = M extends 'single' ? Key | null : Key[]; | ||
| export type ValueType<M extends SelectionMode> = M extends 'single' ? Key | null : readonly Key[]; | ||
| export type ChangeValueType<M extends SelectionMode> = M extends 'single' ? Key | null : Key[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we can remove the null from the change value type for single selection. We already have the disallowEmptySelection option set.
| disallowEmptySelection: selectionMode === 'single', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately can't remove it, there is a way to get null out of this, which is to use the context to setValue(null), which acts like resetting the whole state back to the initial state where nothing is selected.
function SelectClearButton() {
/*- begin highlight -*/
let state = React.useContext(SelectStateContext);
/*- end highlight -*/
return (
<Button
// Don't inherit behavior from Select.
slot={null}
style={{fontSize: 'small', marginTop: 6, padding: 4}}
onPress={() => state?.setValue(null)}>
Clear
</Button>
);
}
Yes, it's a little weird. But we documented it at one point, so I think we've decided we were stuck with it for a while.
| export type SelectionMode = 'single' | 'multiple'; | ||
| export type ValueType<M extends SelectionMode> = M extends 'single' ? Key | null : Key[]; | ||
| export type ValueType<M extends SelectionMode> = M extends 'single' ? Key | null : readonly Key[]; | ||
| export type ChangeValueType<M extends SelectionMode> = M extends 'single' ? Key | null : Key[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately can't remove it, there is a way to get null out of this, which is to use the context to setValue(null), which acts like resetting the whole state back to the initial state where nothing is selected.
function SelectClearButton() {
/*- begin highlight -*/
let state = React.useContext(SelectStateContext);
/*- end highlight -*/
return (
<Button
// Don't inherit behavior from Select.
slot={null}
style={{fontSize: 'small', marginTop: 6, padding: 4}}
onPress={() => state?.setValue(null)}>
Clear
</Button>
);
}
Yes, it's a little weird. But we documented it at one point, so I think we've decided we were stuck with it for a while.
Closes
✅ Pull Request Checklist:
📝 Test Instructions:
🧢 Your Project: