Skip to content

Commit ba5534a

Browse files
Use slot fallback to render optgroup label attr
Instead of setting display:none on the element which holds the label attribute when a legend element is present, we can put the label attribute holding element as a child of a new slot for the legend element, so it automatically gets rendered when there is no legend element. The legend element is only supposed to be the first element in the optgroup as per the content model in the HTML spec, so this patch also enforces that by only slotting the legend element in when it is the first child element. Allowing or using the legend element inside of optgroups was a new feature with customizable select, so compat risk is low. Context: whatwg/html#12201 (comment) There are a11y test expectations because the UA shadowroot is being changed, but this should not be visible to ATs because the new nodes are marked as invisible and ignored, and only appear in the internal "blink" a11y trees as opposed to real platform trees. Change-Id: I776fee963146abbad2028638479df7d3362c35ac Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7629416 Reviewed-by: Joey Arhar <jarhar@chromium.org> Reviewed-by: David Baron <dbaron@chromium.org> Commit-Queue: Joey Arhar <jarhar@chromium.org> Cr-Commit-Position: refs/heads/main@{#1649235}
1 parent ac4b280 commit ba5534a

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<link rel=stylesheet href="resources/customizable-select-styles.css">
3+
4+
<button class=customizable-select-button popovertarget=popover id=button>
5+
<span class=customizable-select-selectedcontent>one</span>
6+
</button>
7+
<div id=popover popover=auto class=customizable-select-popover>
8+
<div class="customizable-select-option selected">one</div>
9+
<div class=customizable-select-optgroup>
10+
<div class=customizable-select-legend>legend</div>
11+
<div class=customizable-select-option>two</div>
12+
</div>
13+
<div class=customizable-select-optgroup>
14+
<div class=customizable-select-legend>label</div>
15+
<div class=customizable-select-option>three</div>
16+
<div class=customizable-select-legend>legend after option</div>
17+
</div>
18+
</div>
19+
20+
<script>
21+
document.getElementById('popover').showPopover({ source: button });
22+
</script>

html/semantics/forms/the-select-element/customizable-select/select-appearance-optgroup-legend-and-label.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html class=reftest-wait>
33
<link rel=author href="mailto:jarhar@chromium.org">
44
<link rel=help href="https://issues.chromium.org/issues/378601807">
5-
<link rel=match href="select-appearance-optgroup-legend-ref.html">
5+
<link rel=match href="select-appearance-optgroup-legend-and-label-ref.html">
66
<meta name=assert content="The legend element should take precedence over the label attribute">
77
<script src="/resources/testdriver.js"></script>
88
<script src="/resources/testdriver-vendor.js"></script>
@@ -23,6 +23,10 @@
2323
<legend>legend</legend>
2424
<option>two</option>
2525
</optgroup>
26+
<optgroup label=label>
27+
<option>three</option>
28+
<legend>legend after option</legend>
29+
</optgroup>
2630
</select>
2731

2832
<script>

0 commit comments

Comments
 (0)