Skip to content

Commit 7a440cb

Browse files
Make customizable select <button> display:contents
This patch makes the <select> element itself handle focus, interaction, and box decorations instead of the child <button> element. This removes a lot of complexity, including delegatesFocus, divergent event handling and button testing, and :-internal-select-has-child-button. This was discussed here: w3c/csswg-drafts#10857 Change-Id: Ia036c6dc08be1b86a50bd96239d08ad19c9a7a6b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6001193 Reviewed-by: David Baron <[email protected]> Commit-Queue: Joey Arhar <[email protected]> Cr-Commit-Position: refs/heads/main@{#1383048}
1 parent 6176095 commit 7a440cb

5 files changed

+11
-52
lines changed

html/semantics/forms/the-select-element/customizable-select/button-in-popover.tentative.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222
<script>
2323
promise_test(async () => {
2424
const select = document.querySelector('select');
25-
const invokerButton = document.getElementById('invoker');
2625
const popoverButton = document.getElementById('popover');
2726

28-
await test_driver.click(invokerButton);
27+
await test_driver.click(select);
2928
assert_true(select.matches(':open'),
3029
'Select should open after clicking the invoker button.');
3130

html/semantics/forms/the-select-element/customizable-select/select-anchor-regression.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
<script>
4141
promise_test(async () => {
42-
await test_driver.click(document.querySelector('button'));
42+
await test_driver.click(document.querySelector('select'));
4343
await new Promise(requestAnimationFrame);
4444
}, 'This test passes if it does not crash.');
4545
</script>

html/semantics/forms/the-select-element/customizable-select/select-disabled.tentative.html

-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@
3434
button.focus();
3535
assert_not_equals(document.activeElement, button,
3636
'select button should not be focusable when select is disabled.');
37-
38-
await test_driver.click(button);
39-
assert_false(select.matches(':open'),
40-
'select should not be open after clicking button when disabled.');
4137
}
4238
}, `${id}: <select disabled> should prevent focus and activation with appearance:base-select.`);
4339
});

html/semantics/forms/the-select-element/customizable-select/select-keyboard-behavior.tentative.html

+7-38
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,7 @@
6868

6969
promise_test(async t => {
7070
addCloseCleanup(t);
71-
// TODO(http://crbug.com/1350299): When focus for custom buttons is fixed,
72-
// then we shouldn't need to explicitly focus the custom button like this
73-
// anymore.
74-
const customButton = select.querySelector('button');
75-
if (customButton) {
76-
customButton.focus();
77-
} else {
78-
select.focus();
79-
}
71+
select.focus();
8072
assert_false(select.matches(':open'),
8173
'The select should initially be closed.');
8274
await test_driver.send_keys(document.activeElement, Space);
@@ -85,7 +77,7 @@
8577
'The select should be open after pressing space.');
8678

8779
await test_driver.send_keys(document.activeElement, Escape);
88-
assert_equals(document.activeElement, customButton ? customButton : select,
80+
assert_equals(document.activeElement, select,
8981
'After dismissing the popover, the invoker button should be focused again.');
9082
}, `${id}: When the listbox is closed, spacebar should open the listbox.`);
9183

@@ -131,15 +123,7 @@
131123
promise_test(async t => {
132124
addCloseCleanup(t);
133125

134-
// TODO(http://crbug.com/1350299): When focus for custom buttons is fixed,
135-
// then we shouldn't need to explicitly use the custom button like this
136-
// anymore.
137-
const customButton = select.querySelector('button');
138-
if (customButton) {
139-
await test_driver.send_keys(customButton, Enter);
140-
} else {
141-
await test_driver.send_keys(select, Enter);
142-
}
126+
await test_driver.send_keys(select, Enter);
143127
await new Promise(requestAnimationFrame);
144128
assert_false(select.matches(':open'),
145129
'Enter should not open the listbox when outside a form.');
@@ -150,11 +134,7 @@
150134
event.preventDefault();
151135
formWasSubmitted = true;
152136
}, {once: true});
153-
if (customButton) {
154-
await test_driver.send_keys(customButton, Enter);
155-
} else {
156-
await test_driver.send_keys(select, Enter);
157-
}
137+
await test_driver.send_keys(select, Enter);
158138
await new Promise(requestAnimationFrame);
159139
assert_true(formWasSubmitted,
160140
'Enter should submit the form when the listbox is closed.');
@@ -214,14 +194,8 @@
214194
promise_test(async t => {
215195
addCloseCleanup(t);
216196

217-
const customButton = select.querySelector('button');
218-
if (customButton) {
219-
customButton.focus();
220-
await test_driver.send_keys(customButton, Space);
221-
} else {
222-
select.focus();
223-
await test_driver.send_keys(select, Space);
224-
}
197+
select.focus();
198+
await test_driver.send_keys(select, Space);
225199
assert_true(select.matches(':open'),
226200
'Space should open the listbox.');
227201
assert_equals(document.activeElement, select.querySelector('.one'),
@@ -234,12 +208,7 @@
234208
// TODO(crbug.com/40263709): Remove this blur when focus on close is improved.
235209
document.activeElement.blur();
236210

237-
if (customButton) {
238-
customButton.focus();
239-
await test_driver.send_keys(customButton, Space);
240-
} else {
241-
await test_driver.send_keys(select, Space);
242-
}
211+
await test_driver.send_keys(select, Space);
243212
assert_true(select.matches(':open'),
244213
'Second space should open the listbox.');
245214
assert_equals(document.activeElement, select.querySelector('.one'),

html/semantics/forms/the-select-element/customizable-select/select-mouse-behavior.tentative.html

+2-7
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,8 @@
7474

7575
promise_test(async () => {
7676
await test_driver.click(label);
77-
if (button) {
78-
assert_equals(document.activeElement, button,
79-
'select child button should be the active element after clicking the label.');
80-
} else {
81-
assert_equals(document.activeElement, select,
82-
'select should be the active element after clicking the label.');
83-
}
77+
assert_equals(document.activeElement, select,
78+
'select should be the active element after clicking the label.');
8479
assert_false(select.matches(':open'),
8580
'select picker should be closed after clicking the label.');
8681
}, `${id}: Clicking the label should focus the select button without opening the picker.`);

0 commit comments

Comments
 (0)