Skip to content

Commit

Permalink
Move the pop-up "show" event earlier and make it cancelable
Browse files Browse the repository at this point in the history
Per [1], there's a desire from Mozilla to move the show event
earlier in the process, and make it cancelable. I see no issues
with doing that, so pending a discussion (at [1]), I'm going to
make this change.

[1] openui/open-ui#579

Bug: 1307772
Change-Id: I87fcec84146f99434bb88d2af12941a2c9156586
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3826329
Reviewed-by: Joey Arhar <jarhar@chromium.org>
Auto-Submit: Mason Freed <masonf@chromium.org>
Commit-Queue: Mason Freed <masonf@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1035213}
  • Loading branch information
mfreed7 authored and chromium-wpt-export-bot committed Aug 15, 2022
1 parent 5522938 commit 6929d9a
Showing 1 changed file with 49 additions and 26 deletions.
75 changes: 49 additions & 26 deletions html/semantics/popups/popup-events.tentative.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,54 @@
<div popup>Popup</div>

<script>
promise_test(async t => {
const popup = document.querySelector('[popup]');
let showCount = 0;
let hideCount = 0;
await new Promise(resolve => window.addEventListener('load',() => resolve()));
assert_false(popup.matches(':top-layer'));
document.addEventListener('show',() => ++showCount);
document.addEventListener('hide',() => ++hideCount);
assert_equals(0,showCount);
assert_equals(0,hideCount);
popup.showPopUp();
assert_true(popup.matches(':top-layer'));
assert_equals(1,showCount);
assert_equals(0,hideCount);
await waitForRender();
assert_true(popup.matches(':top-layer'));
popup.hidePopUp();
assert_false(popup.matches(':top-layer'));
assert_equals(1,showCount);
assert_equals(1,hideCount);
await waitForRender();
// No additional events after animation frame
assert_false(popup.matches(':top-layer'));
assert_equals(1,showCount);
assert_equals(1,hideCount);
}, 'Show and hide events get properly dispatched for popups');
window.onload = () => {
promise_test(async t => {
const popup = document.querySelector('[popup]');
let showCount = 0;
let hideCount = 0;
assert_false(popup.matches(':top-layer'));
const controller = new AbortController();
const signal = controller.signal;
t.add_cleanup(() => controller.abort());
document.addEventListener('show',() => ++showCount, {signal});
document.addEventListener('hide',() => ++hideCount, {signal});
assert_equals(0,showCount);
assert_equals(0,hideCount);
popup.showPopUp();
assert_true(popup.matches(':top-layer'));
assert_equals(1,showCount);
assert_equals(0,hideCount);
await waitForRender();
assert_true(popup.matches(':top-layer'));
popup.hidePopUp();
assert_false(popup.matches(':top-layer'));
assert_equals(1,showCount);
assert_equals(1,hideCount);
await waitForRender();
// No additional events after animation frame
assert_false(popup.matches(':top-layer'));
assert_equals(1,showCount);
assert_equals(1,hideCount);
}, 'Show and hide events get properly dispatched for popups');

promise_test(async t => {
const popUp = document.querySelector('[popup]');
const controller = new AbortController();
const signal = controller.signal;
t.add_cleanup(() => controller.abort());
let cancel = true;
popUp.addEventListener('show',(e) => {
if (cancel)
e.preventDefault();
}, {signal});
assert_false(popUp.matches(':top-layer'));
popUp.showPopUp();
assert_false(popUp.matches(':top-layer'),'The "show" event should be cancelable');
cancel = false;
popUp.showPopUp();
assert_true(popUp.matches(':top-layer'));
popUp.hidePopUp();
assert_false(popUp.matches(':top-layer'));
}, 'Show event is cancelable');
};
</script>

0 comments on commit 6929d9a

Please sign in to comment.