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

refactor!: return a marker string to help Flow detect bad input #8413

Merged
merged 7 commits into from
Dec 31, 2024

Conversation

vursen
Copy link
Contributor

@vursen vursen commented Dec 30, 2024

Description

This PR changes number fields to make the _inputElementValue getter return a NaN marker string when input can't be parsed. This change will allow us to replace _hasInputValue with _inputElementValue in Flow NumberField and then deprecate it in the web components. Previously, detecting bad input via _inputElementValue wasn't possible since input[type=number] elements give an empty string for unparsable values.

Since _inputElementValue is a protected method, I marked this as a possible breaking change

Type of change

  • Bugfix

@vursen vursen marked this pull request as ready for review December 31, 2024 06:41
* @private
*/
get __hasUnparsableValue() {
return this.inputElement.validity.badInput;
get __unparsableValue() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found the previous approach with the boolean getter a bit clearer, and it looks like we don't necessarily have to change this. Having an unparsable value string if the value is parsable is potentially confusing. A boolean expresses this clearer because either the value parsable or not, and that is all we are interested in.

Copy link
Contributor Author

@vursen vursen Dec 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I reverted the previous approach and also added an undefined check to the _inputElementValue getter that's necessary for the Flow ITs to pass.

* @param {InputEvent} event
* @protected
*/
_setHasInputValue(event) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also remove this method from input-mixin.d.ts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@vursen vursen merged commit 8e8ce8a into main Dec 31, 2024
9 checks passed
@vursen vursen deleted the refactor/use-bad-input-marker branch December 31, 2024 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants