Skip to content

Commit 341d90a

Browse files
Close popover stack when popovertarget attribute changes
If the popovertarget attribute is changed on an element in a way which breaks the connection keeping multiple popovers open, then this patch will close all open popovers. This was pointed out here: whatwg/html#9048 (comment) Bug: 1307772, 1408546 Change-Id: I0a42260e97b7ef3fde01f416ef090b50994b8c5d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4354171 Commit-Queue: Joey Arhar <[email protected]> Reviewed-by: Mason Freed <[email protected]> Cr-Commit-Position: refs/heads/main@{#1120013}
1 parent 7312c24 commit 341d90a

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

html/semantics/popovers/popover-target-element-disabled.html

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,53 @@
124124
'The outer popover be should be closed when the hierarchy is broken.');
125125
}, 'Disconnecting popover*target buttons when popovers are open should close all popovers.');
126126
</script>
127+
128+
<div id=outerpopover7 popover=auto>
129+
<button id=togglebutton7 popovertarget=innerpopover7>toggle popover</button>
130+
</div>
131+
<div id=innerpopover7 popover=auto>popover</div>
132+
<script>
133+
test(() => {
134+
outerpopover7.showPopover();
135+
innerpopover7.showPopover();
136+
assert_true(innerpopover7.matches(':open'),
137+
'The inner popover should be able to open successfully.');
138+
assert_true(outerpopover7.matches(':open'),
139+
'The outer popover should stay open when opening the inner one.');
140+
141+
togglebutton7.setAttribute('popovertarget', 'otherpopover7');
142+
assert_false(innerpopover7.matches(':open'),
143+
'The inner popover be should be closed when the hierarchy is broken.');
144+
assert_false(outerpopover7.matches(':open'),
145+
'The outer popover be should be closed when the hierarchy is broken.');
146+
}, 'Changing the popovertarget attribute to break the chain should close all popovers.');
147+
</script>
148+
149+
<div id=outerpopover8 popover=auto>
150+
<div id=middlepopover8 popover=auto>
151+
<div id=innerpopover8 popover=auto>hello</div>
152+
</div>
153+
</div>
154+
<div id=otherpopover8 popover=auto>other popover</div>
155+
<button id=togglebutton8 popovertarget=middlepopover8>other button</div>
156+
<script>
157+
test(() => {
158+
outerpopover8.showPopover();
159+
middlepopover8.showPopover();
160+
innerpopover8.showPopover();
161+
assert_true(innerpopover8.matches(':open'),
162+
'The inner popover should be able to open successfully.');
163+
assert_true(middlepopover8.matches(':open'),
164+
'The middle popover should stay open when opening the inner one.');
165+
assert_true(outerpopover8.matches(':open'),
166+
'The outer popover should stay open when opening the inner one.');
167+
168+
togglebutton8.setAttribute('popovertarget', 'otherpopover8');
169+
assert_true(innerpopover8.matches(':open'),
170+
'The inner popover should remain open.');
171+
assert_true(middlepopover8.matches(':open'),
172+
'The middle popover should remain open.');
173+
assert_true(outerpopover8.matches(':open'),
174+
'The outer popover should remain open.');
175+
}, `Modifying popovertarget on a button which doesn't break the chain shouldn't close any popovers.`);
176+
</script>

0 commit comments

Comments
 (0)