-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close the dialog element when the open attribute is removed
This patch adds HTMLDialogElement::ParseAttribute which runs HTMLDialogElement::close when the open attribute is removed to prevent a bad state where the dialog is modal but hidden and inerting the rest of the document. Spec discussion is happening here: whatwg/html#5802 Change-Id: Ib90736ced952d7aeadc791c6863c3ac2a55deb62
- Loading branch information
1 parent
12a51d9
commit 33caa50
Showing
2 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
html/semantics/interactive-elements/the-dialog-element/dialog-close-via-attribute.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<!DOCTYPE html> | ||
<link rel=author href="mailto:[email protected]"> | ||
<link rel=help href="https://github.com/whatwg/html/issues/5802"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/testdriver.js"></script> | ||
<script src="/resources/testdriver-vendor.js"></script> | ||
|
||
<button>button</button> | ||
<dialog>hello world</dialog> | ||
|
||
<script> | ||
const dialog = document.querySelector('dialog'); | ||
const button = document.querySelector('button'); | ||
|
||
promise_test(async () => { | ||
dialog.showModal(); | ||
|
||
let closeFired = false; | ||
let cancelFired = false; | ||
dialog.addEventListener('close', () => closeFired = true); | ||
dialog.addEventListener('cancel', () => cancelFired = true); | ||
|
||
dialog.removeAttribute('open'); | ||
await new Promise(requestAnimationFrame); | ||
|
||
assert_false(dialog.matches(':modal'), | ||
'The dialog should not match :modal after closing.'); | ||
assert_false(cancelFired, | ||
'The cancel event should not fire when removing the open attribute.'); | ||
assert_true(closeFired, | ||
'The close event should be fired when removing the open attribute.'); | ||
|
||
let buttonFiredClick = false; | ||
button.addEventListener('click', () => buttonFiredClick = true); | ||
await test_driver.click(button); | ||
assert_true(buttonFiredClick, | ||
'The page should not be inert or blocked after removing the open attribute.'); | ||
}, 'Removing the open attribute from an open modal dialog should run the closing algorithm.'); | ||
|
||
promise_test(async () => { | ||
dialog.show(); | ||
|
||
let closeFired = false; | ||
let cancelFired = false; | ||
dialog.addEventListener('close', () => closeFired = true); | ||
dialog.addEventListener('cancel', () => cancelFired = true); | ||
|
||
dialog.removeAttribute('open'); | ||
await new Promise(requestAnimationFrame); | ||
|
||
assert_false(cancelFired, | ||
'The cancel event should not fire when removing the open attribute.'); | ||
assert_true(closeFired, | ||
'The close event should be fired when removing the open attribute.'); | ||
}, 'Removing the open attribute from an open non-modal dialog should fire a close event.'); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters