Skip to content

Commit

Permalink
Run focus async when removing open attribute
Browse files Browse the repository at this point in the history
https: //github.com/whatwg/html/pull/10124#discussion_r1483640232
Change-Id: Iab20699b345d96a8cffc83f7e7e44f4a03feb833
  • Loading branch information
josepharhar authored and chromium-wpt-export-bot committed Feb 9, 2024
1 parent c0538d5 commit 425499b
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
const button = document.querySelector('button');

promise_test(async t => {
button.focus();
dialog.showModal();

let closeFired = false;
Expand All @@ -32,6 +33,9 @@
assert_true(closeFired,
'The close event should be fired when removing the open attribute.');

assert_equals(document.activeElement, button,
'The previously focused element should be focused after removing the open attribute.');

let buttonFiredClick = false;
button.addEventListener('click', () => buttonFiredClick = true);
await test_driver.click(button);
Expand All @@ -40,6 +44,7 @@
}, 'Removing the open attribute from an open modal dialog should run the closing algorithm.');

promise_test(async t => {
button.focus();
dialog.show();

let closeFired = false;
Expand All @@ -55,5 +60,8 @@
'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.');

assert_equals(document.activeElement, button,
'The previously focused element should be focused after removing the open attribute.');
}, 'Removing the open attribute from an open non-modal dialog should fire a close event.');
</script>

0 comments on commit 425499b

Please sign in to comment.