From 425499b943d2237e2dc08eb01f8086b78bc82742 Mon Sep 17 00:00:00 2001 From: Joey Arhar Date: Fri, 9 Feb 2024 11:25:26 -0800 Subject: [PATCH] Run focus async when removing open attribute https: //github.com/whatwg/html/pull/10124#discussion_r1483640232 Change-Id: Iab20699b345d96a8cffc83f7e7e44f4a03feb833 --- .../the-dialog-element/dialog-close-via-attribute.html | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/html/semantics/interactive-elements/the-dialog-element/dialog-close-via-attribute.html b/html/semantics/interactive-elements/the-dialog-element/dialog-close-via-attribute.html index 5c2e70f87a6101..cec1cf81fa796a 100644 --- a/html/semantics/interactive-elements/the-dialog-element/dialog-close-via-attribute.html +++ b/html/semantics/interactive-elements/the-dialog-element/dialog-close-via-attribute.html @@ -14,6 +14,7 @@ const button = document.querySelector('button'); promise_test(async t => { + button.focus(); dialog.showModal(); let closeFired = false; @@ -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); @@ -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; @@ -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.');