1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
<!doctype html>
<link rel="author" title="Tim Nguyen" href="https://github.com/nt1m">
<link rel="help" href="https://html.spec.whatwg.org/#the-select-element">
<link rel="help" href="https://drafts.csswg.org/css-writing-modes-4/#block-flow">
<link rel="help" href="https://drafts.csswg.org/cssom-view/#scrolling-area">
<title>Test <select> multiple attribute scroll progression</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<select multiple size="5"></select>
<script>
const select = document.querySelector("select");
for (let i = 0; i < 100; i++) {
const option = document.createElement("option");
option.textContent = `Option ${i + 1}`;
select.appendChild(option);
}
for (const writingMode of ["horizontal-tb", "vertical-lr", "vertical-rl", "sideways-lr", "sideways-rl"]) {
if (!CSS.supports(`writing-mode: ${writingMode}`))
continue;
const scrollBlockAxis = (() => {
switch (writingMode) {
case "horizontal-tb":
return "scrollTop";
case "vertical-lr":
case "sideways-lr":
case "vertical-rl":
case "sideways-rl":
return "scrollLeft";
}
})();
const scrollInlineAxis = scrollBlockAxis === "scrollTop" ? "scrollLeft" : "scrollTop";
const isHorizontal = writingMode === "horizontal-tb";
const clientBlock = isHorizontal ? "clientHeight" : "clientWidth";
const clientInline = isHorizontal ? "clientWidth" : "clientHeight";
const scrollBlock = isHorizontal ? "scrollHeight" : "scrollWidth";
const scrollInline = isHorizontal ? "scrollWidth" : "scrollHeight";
test(t => {
select.scrollTop = select.scrollLeft = 0;
select.style.writingMode = writingMode;
t.add_cleanup(() => {
select.removeAttribute("style");
select.scrollTop = select.scrollLeft = 0;
});
assert_true(
select[scrollBlock] > select[clientBlock],
"select should be scrollable in block axis"
);
assert_equals(
select[scrollInline], select[clientInline],
"select should not be scrollable in inline axis"
);
assert_equals(
select[scrollBlockAxis], 0,
`scrolling is initially at block start for writing-mode: ${writingMode}`
);
const isReversedBlockFlowDirection = writingMode.endsWith("-rl");
select[scrollBlockAxis] = 100;
if (!isReversedBlockFlowDirection) {
assert_true(
select[scrollBlockAxis] > 0,
`Setting ${scrollBlockAxis} to a positive value of the list works for writing-mode: ${writingMode}`
);
} else {
assert_equals(
select[scrollBlockAxis], 0,
`Setting ${scrollBlockAxis} to a positive value of the list does not work for writing-mode: ${writingMode}`
);
}
select[scrollBlockAxis] = -100;
if (isReversedBlockFlowDirection) {
assert_true(
select[scrollBlockAxis] < 0,
`Setting ${scrollBlockAxis} to a negative value of the list works for writing-mode: ${writingMode}`
);
} else {
assert_equals(
select[scrollBlockAxis], 0,
`Setting ${scrollBlockAxis} to a negative value of the list does not work for writing-mode: ${writingMode}`
);
}
select[scrollInlineAxis] = 100;
assert_equals(
select[scrollInlineAxis], 0,
`setting ${scrollInlineAxis} to a positive value should not scroll for writing-mode: ${writingMode}`
);
select[scrollInlineAxis] = -100;
assert_equals(
select[scrollInlineAxis], 0,
`setting ${scrollInlineAxis} to a negative value should not scroll for writing-mode: ${writingMode}`
);
}, `select[multiple][style="writing-mode: ${writingMode}"] scrolls correctly`);
};
</script>
|