Skip to content

Commit b142d76

Browse files
mfreed7moz-wptsync-bot
authored andcommitted
Bug 1931937 [wpt PR 49232] - Implement new behavior for popovers contained within invokers, a=testonly
Automatic update from web-platform-tests Implement new behavior for popovers contained within invokers In this case: ``` <button popovertarget=foo>Activate <div popover id=foo>Clicking me shouldn't close me</div> </button> ``` clicking the button properly activates the popover, however, clicking on the popover itself after that should **not** close the popover. It currently does because the popover click bubbles to the `<button>` and activates the invoker, which toggles the popover closed. This CL changes that behavior so that clicks on the popover in the case above no longer re-invoke the popover. Spec PR: whatwg/html#10770 Bug: 379241451 Change-Id: Iab67127c46a97a081a7818bfd917864729bf8b5c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6026982 Auto-Submit: Mason Freed <[email protected]> Commit-Queue: Mason Freed <[email protected]> Reviewed-by: David Baron <[email protected]> Cr-Commit-Position: refs/heads/main@{#1384498} -- wpt-commits: 50f7c0548260cdc2f11bface1816a283f9314de8 wpt-pr: 49232
1 parent ebbde10 commit b142d76

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8" />
3+
<link rel="author" href="mailto:[email protected]">
4+
<link rel=help href="https://github.com/whatwg/html/pull/10770">
5+
<link rel=help href="https://issues.chromium.org/issues/379241451">
6+
<script src="/resources/testharness.js"></script>
7+
<script src="/resources/testharnessreport.js"></script>
8+
<script src="resources/popover-utils.js"></script>
9+
10+
<button id=case1 popovertarget=popover>Button
11+
<div popover id=popover>
12+
<span class=descendant>Popover</span>
13+
</div>
14+
</button>
15+
16+
<button id=case2 popovertarget=case2 popover>Self link</button>
17+
18+
<button popovertarget=case3>Button
19+
<div popover id=case3>
20+
<span class=descendant>Popover</span>
21+
</div>
22+
</button>
23+
24+
<script>
25+
promise_test(async t => {
26+
const invoker = document.querySelector('#case1');
27+
const popover = invoker.querySelector('[popover]');
28+
const descendant = invoker.querySelector('.descendant');
29+
assert_false(popover.matches(':popover-open'));
30+
invoker.click();
31+
assert_true(popover.matches(':popover-open'));
32+
popover.click();
33+
assert_true(popover.matches(':popover-open'),'Should still be open');
34+
descendant.click();
35+
assert_true(popover.matches(':popover-open'),'Should still be open, even for descendant');
36+
popover.hidePopover();
37+
},'clicking a popover nested inside a button should not re-invoke the popover');
38+
39+
promise_test(async t => {
40+
const element = document.querySelector('#case2');
41+
assert_false(element.matches(':popover-open'));
42+
element.showPopover();
43+
assert_true(element.matches(':popover-open'));
44+
element.click(); // This is a click on the button, which is also the popover
45+
assert_false(element.matches(':popover-open'));
46+
element.hidePopover();
47+
},'corner case: invoker that is also a popover');
48+
49+
promise_test(async t => {
50+
const popover = document.querySelector('#case3');
51+
const outerInvoker = popover.parentElement;
52+
const descendant = popover.querySelector('.descendant');
53+
const innerInvoker = popover.appendChild(document.createElement('button'));
54+
innerInvoker.popoverTargetElement = popover;
55+
assert_false(popover.matches(':popover-open'));
56+
outerInvoker.click();
57+
assert_true(popover.matches(':popover-open'));
58+
descendant.click();
59+
assert_true(popover.matches(':popover-open'),'descendant doesn\'t close popover');
60+
innerInvoker.click();
61+
assert_false(popover.matches(':popover-open'),'inner invoker still works');
62+
},'invoker inside popover still works, even with weird nesting');
63+
</script>

0 commit comments

Comments
 (0)