-
Notifications
You must be signed in to change notification settings - Fork 933
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
Edit typing of selectItem to allow to set null #1149
Conversation
When `items` is a controlled prop, but `selectedItem` is not, it is necessary to manually reset the selectedItem after an action like `SelectedItemClick` has been executed. This PR allows to call `selectItem(undefined)` without having to typecast this at the call site in Typescript strict mode.
@@ -209,7 +209,7 @@ declare module downshift { | |||
openMenu: (cb?: Callback) => void; | |||
closeMenu: (cb?: Callback) => void; | |||
toggleMenu: (otherStateToSet?: {}, cb?: Callback) => void; | |||
selectItem: (item: Item, otherStateToSet?: {}, cb?: Callback) => void; | |||
selectItem: (item: ?Item, otherStateToSet?: {}, cb?: Callback) => void; |
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 never used flow. is this correct syntax? i have copied it from here: https://flow.org/en/docs/types/maybe/
but maybe (hah), rather null
should be explicitly stated instead of a maybe type to disallow undefined
?
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.
ok i changed it to | null
and also edited the state type as well to include null
for selectedItem
, that was missing from the flow types, it was there for the typescript types already
…n typescript types and make `selectItem` parameter explicitly `| null` to exclude `undefined`
Don't you have |
Hm, maybe. I just fear it would reset too much, would need to try. |
I am all for flexibility, but here I think it's a little bit too much. So I am going to ask for a use you can only use Thank you for the feedback! |
I have not yet tried it! The documentation of Also |
Examples on https://www.downshift-js.com/use-combobox use |
Is this something that might be a breaking change? Adding another possiblity (null) shouldn't break anything in someone's typings, am I correct? |
Change in typescript typings is not breaking (function will just allow wider input) |
Then will keep this up for a major version bump. |
Will add these changes in #1415. |
BREAKING CHANGE: updates to useCombobox and useSelect to adhere to the 1.2 version of the ARIA Combobox pattern. Migration guide is available in [this file](https://github.com/downshift-js/downshift/tree/master/src/hooks/MIGRATION_V7.md). Closes #1365. Closes #1239. Contains changes from #1149.
What:
This PR enables to call
selectItem(null)
without having to typecast this at the call site in Typescript strict mode.Why:
When
items
is a controlled prop, butselectedItem
is not, it is necessary to manually reset the selectedItem after an action likeSelectedItemClick
has been executed.How:
Simple ;-)
Checklist:
In the example at https://www.downshift-js.com/use-combobox,
selectItem(null)
is used, so I addednull
and notundefined
.