-
Notifications
You must be signed in to change notification settings - Fork 24
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: avoid using initial step in validation #421
Conversation
ae75415
to
77c3025
Compare
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.
@pekam I think proper fix for this would be to finally refactor things so that step
property (of number field) has no default value. This is not the first time this has caused an issue. But I guess changing that would be a breaking change, so I'm fine with this workaround for now.
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.
If you set a custom step value with an attribute, the internal <input>
's step
becomes "any"
<vaadin-number-field step="1.5"></vaadin-number-field>
setting the min or max property should not trigger step-based validation fix #420
The only problem is that we can't detect when user has set step="1" (default value) as an attribute. In this case it won't validate by step (same as not setting step at all).
77c3025
to
2879d2c
Compare
Fixed by also checking I think this is the best we can do. WDYT? |
@pekam I think you could use Edit: actually maybe not since it has |
@Haprog I've tested that. Unfortunately the |
If we consider the expected behavior to be: But the problem is that it will break one case which was previously working as expected:
Expected: validated with step Although this previously worked just because setting So I'm actually not sure if this can be merged. It is fixing more than it's breaking, but it is breaking something that previously worked. |
I guess we could maybe remove |
That doesn't help in this case since it's initially defined as an attribute, which is reflected to property. It propagates this way even when I'm trying if I can use |
I don't think it matters in this case if it has been propagated from attribute to property already. If |
Well I guess that would only solve the problem with setting it via attribute to |
|
But it seems that we can check if the attribute was set in |
|
D'oh, you're right. Sorry about my brain fart. :D Of course it makes a difference in the case when setting only the property but not the attribute. |
So basically when |
The harder case is if the user tries to set step to 1 (either via attribute or property) after the component is ready/initialized already. (since then the default value 1 is already in both property and attribute and change events might not happen if it's being set to the same value it's at already (I don't remember if it's the same case with setting attribute?). Not sure if it would help to replace |
I have tried overriding the That case at least has an easy workaround: setting the property as a string "1". |
fixes initially invalid test case
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.
Ok, I think this is probably as good as it can be fixed without breaking changes.
I think we should refactor the step
property to not have a default value (but internally default to 1 for calculations if needed) and make a new major alpha version with that breaking change so this situation would improve and simplify the code when we can bump the new major version to stable and include in some later version of platform.
By setting the attribute manually instead of using reflectToAttribute, the step value set as a string gets converted into a number. I'd consider this to be a fix instead of a breaking thing, because the property type is number.
IMO it's not such a big deal that it would be worth to fix for the Polymer-based platform majors, which won't be long-term supported. But when rebuilding with Lit, this should be taken care of. |
I guess so, but I'm mainly thinking if it's not a big effort to change it might be easier to do now so we won't forget about it and implement the same logic with default value when porting to Lit. It would be less refactoring required when doing the Lit version if this part was done already. |
Issue created #435. We can continue discussion on this elsewhere. One more thing, @Haprog do you agree with my latest commit which I pushed after your approval? Read the full commit message for relevant info. |
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 agree
Ok, thanks for the review! :) |
setting the min or max property should not trigger step-based validation
fix #420