Skip to content
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

[Typings] Field type missing from useCombobox / useSelect 's props.onStateChange #1015

Closed
andrei-datcu opened this issue Apr 25, 2020 · 3 comments · Fixed by #985 or #1104
Closed

[Typings] Field type missing from useCombobox / useSelect 's props.onStateChange #1015

andrei-datcu opened this issue Apr 25, 2020 · 3 comments · Fixed by #985 or #1104

Comments

@andrei-datcu
Copy link

  • downshift version: 5.2.0

Problem description:
According to the docs:

changes: These are the properties that actually have changed since the last state change. This also has a type property which you can learn more about in the stateChangeTypes section.

Yet in index.d.ts:

onStateChange?: (changes: Partial<UseComboboxState<Item>>) => void

export interface UseComboboxState<Item> {
  highlightedIndex: number
  selectedItem: Item
  isOpen: boolean
  inputValue: string
}

There's no type field

Suggested solution:
The field seems to be present for useMultipleSelection:

  onStateChange?: (changes: UseMultipleSelectionStateChange<Item>) => void

export interface UseMultipleSelectionStateChange<Item>
  extends Partial<UseMultipleSelectionState<Item>> {
  type: UseMultipleSelectionStateChangeTypes
}

So I guess creating two new interfaces that are extending the Use.*State interfaces seems the most consistent option.

@silviuaavram
Copy link
Collaborator

I took another look at #985 and I think it will fix this, am I right?

@kimroen
Copy link

kimroen commented Jun 6, 2020

I took another look at #985 and I think it will fix this, am I right?

Yes, I believe so!

silviuaavram added a commit that referenced this issue Jul 21, 2020
**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
@silviuaavram
Copy link
Collaborator

🎉 This issue has been resolved in version 6.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants