Skip to content

Commit 2c67022

Browse files
tcaptan-crchromium-wpt-export-bot
authored andcommitted
StepDown should default to min when no current val
When `stepDown()` is called on an input box that has a minimum value defined that is greater than zero and no current value, no value is set. This can seem unintuitive to users and mismatches what currently happens when the user uses the spinner or keyboard down arrow. The reason for nothing seeming to happen is due to interpretation of step 10 in the stepDown(n) method specified algorithm [1]: "10. If either the method invoked was the stepDown() method and value is greater than valueBeforeStepping, or the method invoked was the stepUp() method and value is less than valueBeforeStepping, then return." when applying the default value in step 5: "5. If applying the algorithm to convert a string to a number to the string given by the element's value does not result in an error, then let value be the result of that algorithm. Otherwise, let value be zero." If the minimum value defined for the input is greater than the default of zero, the check in step 10 fails and an early return is executed. The proposed fix for this is to keep track of whether there was an actual `valueBeforeStepping` (current value) or the default is used, and execute the early return defined in step 10 only if the default was not used. This will result in a more intuitive behavior for the users, and align the `stepDown()` behavior in this case with the spinner/keyboard arrow down behavior and also match FireFox. [1]https://html.spec.whatwg.org/multipage/input.html#dom-input-stepup Bug: 40692746 Change-Id: Ie4cabb9169911f8c8cb0149c716133f0a1951cb8 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5474199 Reviewed-by: Mason Freed <[email protected]> Commit-Queue: Traian Captan <[email protected]> Cr-Commit-Position: refs/heads/main@{#1291586}
1 parent 9e7e1bd commit 2c67022

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!DOCTYPE HTML>
2+
<title>Input Step Down</title>
3+
4+
<link rel="help" href="https://html.spec.whatwg.org/multipage/input.html#dom-input-stepup">
5+
6+
<script src="/resources/testharness.js"></script>
7+
<script src="/resources/testharnessreport.js"></script>
8+
9+
<input type='number' id='input'>
10+
11+
<script>
12+
const input = document.getElementById("input");
13+
14+
function testStepDown(initialValue, minValue, expectedValue) {
15+
input.value = initialValue;
16+
input.min = minValue;
17+
18+
input.stepDown();
19+
20+
assert_equals(input.value, expectedValue);
21+
}
22+
23+
const tests = [
24+
{ initialValue: '', minValue: '', expectedValue: '-1', description: 'stepDown() on input with no initial or min values' },
25+
{ initialValue: '', minValue: '7', expectedValue: '7', description: 'stepDown() on input with no initial value and positive min value' },
26+
{ initialValue: '', minValue: '-7', expectedValue: '-1', description: 'stepDown() on input with no initial value and negative min value' },
27+
{ initialValue: '7', minValue: '7', expectedValue: '7', description: 'stepDown() on input with initial value equal to min value' },
28+
{ initialValue: '3', minValue: '7', expectedValue: '3', description: 'stepDown() on input with initial value less than min value' },
29+
{ initialValue: '10', minValue: '7', expectedValue: '9', description: 'stepDown() on input with initial value greater than min value' },
30+
];
31+
32+
for(const t of tests) {
33+
test(()=>{
34+
testStepDown(
35+
t.initialValue,
36+
t.minValue,
37+
t.expectedValue
38+
);
39+
},
40+
t.description);
41+
}
42+
</script>

0 commit comments

Comments
 (0)