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

fix(ts): specify that itemToString can receive null #1075

Merged
merged 1 commit into from
Jun 27, 2020

Conversation

kimroen
Copy link

@kimroen kimroen commented Jun 8, 2020

What:

This makes it so the argument passed to itemToString can be null for the following interfaces:

  • UseSelectProps
  • UseComboboxProps
  • Actions

Why:

This makes them behave in line with various documentation, which states that they can receive null:

How:

I looked for all instances for itemToString in the typescript types and looked up their documentation to determine which ones have been specified to potentially be null. I then added | null to the relevant ones, which will make it so the argument can either be of the Item type or null.

Checklist:

  • Documentation N/A
  • Tests N/A
  • TypeScript Types
  • Flow Types N/A
  • Ready to be merged

I didn’t touch useMultipleSelection, because its documentation didn’t have this line: useMultipleSelection#itemToString

I was also not sure about itemToString passed to the various A11y-functions, so I didn’t touch these either.

This fix has previously been applied to the main Downshift component: #505

This will be a breaking change for people using typescript with strictNullChecks turned on if they don’t already check for null. I will leave that decision with you, though.

This makes it so the argument passed to `itemToString` can be `null` for the following interfaces:

- `UseSelectProps`
- `UseComboboxProps`
- `Actions`

This makes them behave in line with various documentation, which states that they can receive null:

- [`useCombobox#itemToString`](https://github.com/downshift-js/downshift/tree/master/src/hooks/useCombobox#itemtostring)
- [`useSelect#itemToString`](https://github.com/downshift-js/downshift/tree/master/src/hooks/useSelect#itemtostring)
- [Downshift component](https://github.com/downshift-js/downshift#itemtostring)

I didn’t touch `useMultipleSelection`, because its documentation didn’t have this line: [`useMultipleSelection#itemToString`](https://github.com/downshift-js/downshift/tree/master/src/hooks/useMultipleSelection#itemtostring)

I was also not sure about `itemToString` passed to the various `A11y`-functions, so I didn’t touch these either.

This fix has previously been applied to the main Downshift component: downshift-js#505

This will be a breaking change for people using typescript with `strictNullChecks` turned on if they don’t already check for null. I will leave that decision with you, though.
@codecov-commenter
Copy link

Codecov Report

Merging #1075 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #1075   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           17        17           
  Lines         1319      1319           
  Branches       241       241           
=========================================
  Hits          1319      1319           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 45985a8...0c542c5. Read the comment docs.

@silviuaavram
Copy link
Collaborator

Awesome! Probably we need to have it in useMultipleSelection as well, I think I've missed that in the Readme. Can you add it as well please? Both Readme and the TS fix. Thank you!

@kimroen
Copy link
Author

kimroen commented Jun 12, 2020

Probably we need to have it in useMultipleSelection as well, I think I've missed that in the Readme.

No, it actually looks like it's not the case in useMultipleSelection! It kind of makes sense - why would it be null for that one?

@silviuaavram
Copy link
Collaborator

Oh, you are right.

Marked this as a Breaking Change and will add it to the v6 branch when I will start it. Thank you!

@silviuaavram silviuaavram changed the base branch from master to v6 June 27, 2020 12:11
@silviuaavram silviuaavram merged commit e1c37ff into downshift-js:v6 Jun 27, 2020
@kimroen kimroen deleted the item-to-string-typings branch June 29, 2020 08:21
silviuaavram added a commit that referenced this pull request 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants