-
Notifications
You must be signed in to change notification settings - Fork 929
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
fix(hooks): add type to on change handler params #985
Conversation
Codecov Report
@@ Coverage Diff @@
## master #985 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 13 13
Lines 1022 1024 +2
Branches 200 200
=========================================
+ Hits 1022 1024 +2
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #985 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 17 17
Lines 1236 1237 +1
Branches 239 239
=========================================
+ Hits 1236 1237 +1
Continue to review full report at Codecov.
|
I actually just went in to fix this myself and saw this PR. What's holding this back? I implemented the fix in a very similar way, but as far as I could tell the How is this a breaking change, by the way? I wouldn't think adding a property would break anything. |
Hi @kimroen! It's breaking as a result of the TypeScript changes. It's already passed to I am waiting to converge a few more PRs with breaking changes before releasing v6. But I don't think that this PR is blocked by anything, as far as I see it it should be ready to be merged. You can review it also and tell me what you think, on both the functionality change and the Typescript changes. Thank you! |
Thanks for the explanation! I don't think I agree that adding a field to an object passed to a function is a breaking change, but I'm not extremely invested and I can go along with it ✨ Regarding the changes, I made pretty much the same change in my own fix, here: In addition to that one though, I actually made another change which I would love your thoughts on: This makes it so the field that is relevant for the specific change callback function it is passed to is not optional. In other words, in the change passed to In practice this looks like this: (Note which fields are optional in the two) Is this something we could be interested in including? If so, I could make a PR for it, but it would conflict pretty heavily with this one, so I wanted to ask 😄 |
Any update on this? |
It's not just adding a field, it's replacing as well, for instance: As for status, please review this @AliTheAli @kimroen and make sure it's ready to merge. It will be included in the next major release. I want to merge a few more breaking change PRs into it so that is why I am not merging it right now. |
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.
Regarding this comment:
It's not just adding a field, it's replacing as well, for instance:
onInputValueChange?: (changes: Partial<UseComboboxState>) => void
with
onSelectedItemChange?: (changes: Partial<UseComboboxState>) => void
which is different (and correct).
I don't see this change in your PR - are you saying you renamed onInputValueChange
to onSelectedItemChange
, or is there another difference here that I'm supposed to be seeing?
typings/index.d.ts
Outdated
|
||
export interface UseSelectDispatchAction { | ||
type: UseSelectStateChangeTypes | ||
[data: string]: any |
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.
This key that has a key of string
and a value of any
is going to make autocomplete a little less useful - do we not have anything more complete we could put here instead, or is it entirely user-defined?
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.
Oups, edited with the acutal line of onInputValueChange
.
That line with [data:string]: any is because the dispatch may have stuff in it required to change the state. Do you have a better suggestion?
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.
If we don't know what that "stuff" is ahead of time then it might be okay, but if we do then we should try to be more specific in the type. If we don't know, then it would be better (for typescript) if all the unknown fields are in a separate object so we can limit the unknowns to one place without polluting the main change object.
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 think we can determine what the fields are by going through all the dispatch calls in the hooks and add those fields as optional. Would that be ok?
@kimroen thank you for suggesting to update the types for |
fcf116e
to
828d0e2
Compare
This is so much better, thank you very much! ✨ |
**What**: Update downshift to v6. **Why**: Introduce breaking changes that fix the issues below. Fixes #1088. Fixes #1015. Fixes #1010. Fixes #719. **How**: **The list of breaking changes:** BREAKING CHANGE: Update TS typings for `selectedItem` to accept `null` in both `useSelect` and `useCombobox`. To migrate to the new change, update your types or code if necessary. `selectedItem`, `defaultSelectedItem` and `initialSelectedItem` now have `Item | null` instead of `Item` type. PR with the changes: #1090 BREAKING CHANGE: Update TS typings for `itemToString` to accept `null` for the `item` parameter, in `useSelect` and `useCombobox` + in `Downshift` where this was missing. `useMultipleSelection` type for `itemToString` stays the same as it can't receive `null` as `item`. To migrate to the new change, update your types or code if necessary. `itemToString: (item: Item) => string` -> `itemToString: (item: Item | null) => string}`. PR with the changes: #1075 #1105 BREAKING CHANGE: Pass `type` to the onChange (onInputValueChange, onHighlightedIndexChange, onSelectedItemChange, onIsOpenChange) handler parameters, as specified in the documentation. Also updated the TS typings to reflect this + `onStateChange` - the `type` parameter was passed but it was not reflected in the TS types. To migrate to the new change, update your types or code if necessary, better to view the changes in the PR: #985. BREAKING BEHAVIOUR [useCombobox]: When an item is highlighted by keyboard and user closes the menu using mouse/touch, the item is not selected anymore. The only selection on Blur happens using either Tab / Shift+Tab. PR with the changes: #1109 BREAKING BEHAVIOUR [useCombobox & downshift]: When pressing Escape and the menu is open, only close the menu. When the menu is closed and there is an item selected and/or text in the input, clear the selectedItem and the inputValue. PR with the changes: #719
What:
As discussed here we are adding
type
to other handlers as we claim to support this already in the docs.Why:
We already claim to support these. We already pass
type
inonStateChange
.Fixes #1015.
How:
type
in other chance handlers as well (onIsOpenChange
,onSelectedItemChange
etc.)props
from thestateReducer
call paramactionAndChanges
. Now it should be called with{...action, changes}
, whereaction
has atype
and other data passed by the hook in dispatch.stateReducer
in both hooks to reflect it's being called with{...action, changes}
.Checklist: