-
Notifications
You must be signed in to change notification settings - Fork 82
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!: use inputmode instead of number type #3071
Conversation
5e43116
to
30bef49
Compare
@@ -441,6 +460,16 @@ export class NumberField extends InputFieldMixin(SlotStylesMixin(ThemableMixin(E | |||
super._valueChanged(this.value, oldVal); | |||
} | |||
|
|||
/** @private */ | |||
__isValidByStep(value) { |
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.
Something fishy about the validation. With the following:
<vaadin-number-field label="Required" required step="0.3"></vaadin-number-field>
if I focus the field and hit up arrow 3 times so that the value is 0.9, the field becomes invalid when blurred.
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, I will add tests for fractional steps.
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.
@tomivirkki Fixed, and added validate()
calls to existing tests for problematic values.
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.
The following number field still claims to be invalid if I change the value with arrow keys:
<vaadin-number-field min="1" step="0.3"></vaadin-number-field>
Since BigDecimalField sets the decimal separator (for the |
e8d4a47
to
e67a53a
Compare
Created an issue to handle it separately for the sake of cleaner release notes: #3096 |
6e07b9d
to
3b83493
Compare
We might want to change |
|
||
/** | ||
* Handle problematic values when calculating a remainder. | ||
* Source: Source: https://stackoverflow.com/a/31711034 |
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.
* Source: Source: https://stackoverflow.com/a/31711034 | |
* Source: https://stackoverflow.com/a/31711034 |
) { | ||
return this.inputElement.checkValidity(); | ||
if (this.value == null || this.value == '') { |
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.
The input value should be sanitized so that the field wouldn't get a non-numeric value
and the validation works as expected:
With the following
<vaadin-number-field step="0.5"></vaadin-number-field>
typed value | field value | invalid |
---|---|---|
"0.5" | "0.5" | false |
"0,5" | "0,5" | true |
".5" | ".5" | false |
",5" | "" | false |
"1-" | "1-" | true |
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.
It looks like there are some assumptions about localization in this table. For me 0,5
is certainly a valid value. Same for ,5
, which results in an input value of 0.5
, when comparing the behaviour with a native number input in Firefox.
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.
Clarification: The table represent how the current revision of the PR works
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, I will update the validation logic to cover values with ,
separator.
type: Number, | ||
value: 1, | ||
observer: '_stepChanged' | ||
type: Number | ||
} | ||
}; |
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.
Let's use _enabledCharPattern
in number field also to prevent user from typing arbitrary characters.
) { | ||
return this.inputElement.checkValidity(); | ||
if (this.value == null || this.value == '') { |
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.
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'm not very enthusiastic about the keyboard layout detection feature. It looks brittle, and neither of the linked tickets are about implementing such a feature.
Also the main issue of the first ticket (#1169) is that preventing invalid inputs should work consistently between browsers, which isn't addressed at all here.
return super.checkValidity(); | ||
} else { | ||
// Mimic validation logic provided by native `<input type="number">` as we don't use it. | ||
return !(this.value > this.max || this.value < this.min || !this.__isValidByStep(this.value)); |
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 does not cover the native input validation logic regarding localization. Setting a min of 1.5
and entering a value of 1,3
, which is an internal value of 1.3
, does not mark the input invalid.
Also value
is still a string, while min
and max
are numbers, which indicates an implicit type coersion in the comparison. Value should be parsed to a number instead, which of course requires us to take the users locale into account.
I also could not find any tests regarding this validation. I assume the previous version relied on the fact that the browser implemented this check. Now that we are doing this on our own we would need tests to cover it.
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.
Thank you for very valid points regarding the implementation. I will update the PR accordingly tomorrow.
3b83493
to
682f4cc
Compare
682f4cc
to
5b5fdde
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Short summary from a meeting where we discussed the ticket that this PR is targeting:
|
Description
<input type="text">
but not extendvaadin-text-field
for now (IMO, that should be done separately, because it would also mean having to bring backpattern
andpreventInvalidInput
properties and tests for them).AbstractNumberField
because we no longer use<input type="number">
and can't rely on its built-in logic. Note, the Flow counterpart will still override client-side validation.Fixes #1169
Fixes #1224
Type of change
Checklist