Skip to content

Commit 9656b43

Browse files
committed
[BUGFIX beta] Fix range input values
If an input a type range is set after value but before min and max, it produces different results than done in markup. Given IE9 does not support range inputs, tests first make sure that the type of the input is range. Closes #15675
1 parent 6c5db5a commit 9656b43

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

packages/ember-glimmer/lib/components/text_field.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ export default Component.extend(TextSupport, {
7070
'inputmode',
7171
'lang',
7272
'list',
73+
'type', // needs to be before min and max. See #15675
7374
'max',
7475
'min',
7576
'multiple',
7677
'name',
7778
'pattern',
7879
'size',
7980
'step',
80-
'type',
8181
'value',
8282
'width'
8383
],

packages/ember-glimmer/tests/integration/helpers/input-test.js

+53
Original file line numberDiff line numberDiff line change
@@ -653,3 +653,56 @@ moduleFor(`Helpers test: {{input type='text'}}`, class extends InputRenderingTes
653653
this.assertAttr('tabindex', undefined);
654654
}
655655
});
656+
657+
// These are the permutations of the set:
658+
// ['type="range"', 'min="-5" max="50"', 'value="%x"']
659+
[
660+
'type="range" min="-5" max="50" value="%x"',
661+
'type="range" value="%x" min="-5" max="50"',
662+
'min="-5" max="50" type="range" value="%x"',
663+
'min="-5" max="50" value="%x" type="range"',
664+
'value="%x" min="-5" max="50" type="range"',
665+
'value="%x" type="range" min="-5" max="50"',
666+
].forEach(attrs => {
667+
moduleFor(`[GH#15675] Helpers test: {{input ${attrs}}}`, class extends InputRenderingTest {
668+
renderInput(value = 25) {
669+
this.render(`{{input ${ attrs.replace("%x", value) }}}`);
670+
}
671+
672+
assertValue(expected) {
673+
let type = this.$input().attr('type');
674+
675+
if (type !== 'range') {
676+
this.assert.ok(true, 'IE9 does not support range items');
677+
return;
678+
}
679+
680+
super.assertValue(expected);
681+
}
682+
683+
['@test value over default max but below set max is kept'](assert) {
684+
this.renderInput("25");
685+
this.assertValue("25");
686+
}
687+
688+
['@test value below default min but above set min is kept'](assert) {
689+
this.renderInput("-2");
690+
this.assertValue("-2");
691+
}
692+
693+
['@test in the valid default range is kept'](assert) {
694+
this.renderInput("5");
695+
this.assertValue("5");
696+
}
697+
698+
['@test value above max is reset to max'](assert) {
699+
this.renderInput("55");
700+
this.assertValue("50");
701+
}
702+
703+
['@test value below min is reset to min'](assert) {
704+
this.renderInput("-10");
705+
this.assertValue("-5");
706+
}
707+
});
708+
});

0 commit comments

Comments
 (0)