Skip to content

Commit a634fb2

Browse files
keithamusmoz-wptsync-bot
authored andcommitted
Fix edge case: click events inside buttons with popover descendants
Given a structure like: ``` <button popovertarget=foo>Activate <div popover id=foo>Clicking me shouldn't close me</div> </button> ``` With the popover open, clicking the popover will propagate a click upward to the button, which will close the button. This change ensures that the original target is checked, and if it is a ShadowIncludingDescendantOf the button then the popover behaviour is not invoked. Differential Revision: https://phabricator.services.mozilla.com/D259955 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1932700 gecko-commit: c966ce3fbecccc0f8d0f08f373a600d71d9a2f7a gecko-reviewers: dom-core, smaug
1 parent d1b734d commit a634fb2

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

html/semantics/popovers/popover-nested-in-button.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@
2121
</div>
2222
</button>
2323

24+
<div id=case4>
25+
<template shadowrootmode=open>
26+
<button popovertarget=case4>Button
27+
<div popover id=case4>
28+
<span class=descendant>Popover</span>
29+
</div>
30+
</button>
31+
</template>
32+
</div>
33+
2434
<script>
2535
promise_test(async t => {
2636
const invoker = document.querySelector('#case1');
@@ -60,4 +70,15 @@
6070
innerInvoker.click();
6171
assert_false(popover.matches(':popover-open'),'inner invoker still works');
6272
},'invoker inside popover still works, even with weird nesting');
73+
74+
promise_test(async t => {
75+
const popover = document.querySelector('#case4').shadowRoot.querySelector('[popover]');
76+
const invoker = popover.parentElement;
77+
const descendant = popover.querySelector('.descendant');
78+
assert_false(popover.matches(':popover-open'));
79+
invoker.click();
80+
assert_true(popover.matches(':popover-open'));
81+
descendant.click();
82+
assert_true(popover.matches(':popover-open'),'descendant doesn\'t close popover');
83+
},'invoker inside popover still works, even inside of a shadowroot');
6384
</script>

0 commit comments

Comments
 (0)