From 5e24198eada48bd87cd5397e7a5b0659091dc688 Mon Sep 17 00:00:00 2001 From: Mason Freed Date: Fri, 18 Nov 2022 10:10:29 -0800 Subject: [PATCH] Move hide event before state changes on `:open` Move the timing of the popover `popoverhide` event a bit earlier in the process, just *before* the state changes to "transitioning". This has the effect of making the state clean (either :open or :closed) for both `popoverhide` and `popovershow`. See the discussion here: https://github.com/openui/open-ui/issues/607 Bug: 1307772 Change-Id: I5aaabfd48204e54831ce435c71a54e692e139caf --- .../popovers/popover-events.tentative.html | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/html/semantics/popovers/popover-events.tentative.html b/html/semantics/popovers/popover-events.tentative.html index 2f530d1adea7410..78d4a22c78e7be4 100644 --- a/html/semantics/popovers/popover-events.tentative.html +++ b/html/semantics/popovers/popover-events.tentative.html @@ -17,21 +17,31 @@ assert_false(popover.matches(':open')); let showCount = 0; let hideCount = 0; + function showListener(e) { + assert_true(e.target.matches(':closed'),'The popover should be in the :closed state when the popovershow event fires.'); + assert_false(e.target.matches(':open'),'The popover should *not* be in the :open state when the popovershow event fires.'); + ++showCount; + }; + function hideListener(e) { + assert_true(e.target.matches(':open'),'The popover should be in the :open state when the popoverhide event fires.'); + assert_false(e.target.matches(':closed'),'The popover should *not* be in the :closed state when the popoverhide event fires.'); + ++hideCount; + }; switch (method) { case "listener": const controller = new AbortController(); const signal = controller.signal; t.add_cleanup(() => controller.abort()); - document.addEventListener('popovershow',() => ++showCount, {signal}); - document.addEventListener('popoverhide',() => ++hideCount, {signal}); + document.addEventListener('popovershow',showListener, {signal}); + document.addEventListener('popoverhide',hideListener, {signal}); break; case "attribute": assert_false(popover.hasAttribute('onpopovershow')); assert_false(popover.hasAttribute('onpopoverhide')); t.add_cleanup(() => popover.removeAttribute('onpopovershow')); t.add_cleanup(() => popover.removeAttribute('onpopoverhide')); - popover.onpopovershow = () => ++showCount; - popover.onpopoverhide = () => ++hideCount; + popover.onpopovershow = showListener; + popover.onpopoverhide = hideListener; break; default: assert_unreached(); }