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

The validation to number step is wrong #86

Open
cyfung1031 opened this issue Jan 4, 2023 · 4 comments
Open

The validation to number step is wrong #86

cyfung1031 opened this issue Jan 4, 2023 · 4 comments

Comments

@cyfung1031
Copy link

cyfung1031 commented Jan 4, 2023

@var range      param-1                 "Param 1"                               [12, 0, 36, 4, 'px']

Why I cannot set it to zero? When it become zero, it is just 12px
[updated: 2023.03.10 - I can no longer reproduce this issue; the default value issue can be closed.]

@var range      param-2                 "Param 2"                               [15, 3, 39, 4, 'px']

Why this is not allowed?

@eight04
Copy link
Collaborator

eight04 commented Mar 9, 2023

@tophf

Currently, we always assume the number is a multiple of step, which doesn't match browser's input[number]:

Only values which are equal to the basis for stepping (min if specified, value otherwise, ...) are valid
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number

.some(n => n != null && !isMultipleOf(n, result.step))

Which should be changed to:

      .some(n => n != null && !canStepTo(basis, n, result.step))

However, this will be a breaking change, that value won't be a multiple of step anymore. WDYT?

@eight04 eight04 changed the title @var default value The validation to number step is wrong Mar 9, 2023
@tophf
Copy link
Member

tophf commented Mar 9, 2023

The article says

When the data entered by the user doesn't adhere to the stepping configuration, the user agent may round to the nearest valid value, preferring numbers in the positive direction when there are two equally close options

so I think we should just forcefully snap min, max, default to the nearest step-multiple and emit a warning.

@eight04
Copy link
Collaborator

eight04 commented Mar 10, 2023

When the data entered by the user doesn't adhere to the stepping configuration, the user agent may round to the nearest valid value, preferring numbers in the positive direction when there are two equally close options

so I think we should just forcefully snap min, max, default to the nearest step-multiple and emit a warning.

I think it refers to user-input value, especially on a range input. The value will stick to nearest snap point automatically.

The issue in the OP is that, the following input is valid:

<input type=number value=1 min=1 max=5 step=2>

But the following code is not valid in usercss-meta:

@var number foo "Foo" [1, 1, 5, 2]

@tophf
Copy link
Member

tophf commented Mar 10, 2023

So the correct check should be value - min is a multiple of step, and if our check was wrong it doesn't matter that fixing it will be a breaking change. I expect most styles won't be affected because they were already using min/max that are a multiple of step.

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

No branches or pull requests

3 participants