-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[Autocomplete] Zero (0) integer key display throws #18994
Conversation
Details of bundle changes.Comparing: 50601ce...661a6d4
|
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.
Thanks for working on this. I'll add a test. Once that is done this seems mergable.
@@ -233,7 +233,7 @@ export default function useAutocomplete(props) { | |||
const open = isOpenControlled ? openProp : openState; | |||
|
|||
const inputValueFilter = | |||
!multiple && value && inputValue === getOptionLabel(value) ? '' : inputValue; |
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.
We should start linting against these. It's hidden loose equality checking and I think we had like 5-10 issues the last year concerning these. In a typed language this might be ok (if you know the type already is boolean). In a weakly typed language this is dangerous while not improving readability (I'd say it's even worse). The added bytes is negligible.
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 also remember a few occurrences of this type of bug. It's fascinating to see the length of which the components get battle-tested.
@@ -585,7 +587,7 @@ export default function useAutocomplete(props) { | |||
inputRef.current.value.length, | |||
); | |||
} | |||
} else if (freeSolo && inputValueFilter !== '') { |
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.
Introduced in #18786.
The Enter key shouldn't trigger a new onChange event if its already currently selected.
For future reference: Prefer to codify this explicitly rather than communicating this implicitly with a type (here: the empty string). A variable if (inputValueIsSelectedValue === false)
is more readable than if (inputValueFilter === '')
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.
Sounds fair, it will help our future self.
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.
Great job
@@ -585,7 +587,7 @@ export default function useAutocomplete(props) { | |||
inputRef.current.value.length, | |||
); | |||
} | |||
} else if (freeSolo && inputValueFilter !== '') { |
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.
Sounds fair, it will help our future self.
AddressesFixes #18327.Happy to write some tests here but still getting familiar with the test suite.