Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement dialog initial focus proposal #36831

Merged
merged 1 commit into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions css/css-anchor-position/anchor-position-top-layer-001.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
height: 100px;
background: lime;
anchor-scroll: --a;
outline: none;
}

body {
Expand Down
1 change: 1 addition & 0 deletions css/css-anchor-position/anchor-position-top-layer-002.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
height: 100px;
background: lime;
anchor-scroll: --a;
outline: none;
}

body {
Expand Down
1 change: 1 addition & 0 deletions css/css-anchor-position/anchor-position-top-layer-003.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
height: 100px;
background: lime;
anchor-scroll: --a;
outline: none;
}

body {
Expand Down
1 change: 1 addition & 0 deletions css/css-anchor-position/anchor-position-top-layer-004.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
height: 100px;
background: lime;
anchor-scroll: --a;
outline: none;
}

body {
Expand Down
1 change: 1 addition & 0 deletions css/css-anchor-position/anchor-position-top-layer-005.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
border: 0;
padding: 0;
inset: auto;
outline: none;
}

dialog::backdrop {
Expand Down
1 change: 1 addition & 0 deletions css/css-anchor-position/anchor-position-top-layer-006.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
margin: 0;
border: 0;
padding: 0;
outline: none;
}

dialog::backdrop {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<style>
.box { width: 100px; height: 100px; border: 1px solid black; }
.hidden { content-visibility: hidden }
#dialog { outline: none; }
</style>

<div id=container class=box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

<style>
.box { width: 100px; height: 100px; border: 1px solid black; }
dialog { outline: none; }
</style>

<div id=container class=box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

view-transition-name: dialog;
contain: layout;

outline: none;
}

#target::backdrop {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

view-transition-name: dialog;
contain: layout;

outline: none;
}

#target::backdrop {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
padding: 0px;
border: none;
margin: 0px;
outline: none;
}

#bottom::backdrop {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<link rel=author href="mailto:[email protected]">
<link rel=help href="https://github.com/whatwg/html/pull/8199">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<dialog autofocus id=autofocusdialog data-description="dialog element with autofocus should get initial focus.">
<button>focusable button</button>
<button autofocus class=target>autofocusable button</button>
</dialog>

<dialog id=keyboardfocusdialog data-description="Only keyboard-focusable elements should get dialog initial focus.">
<button tabindex="-1">mouse focusable button</button>
<button class=target>keyboard focusable button</button>
</dialog>

<dialog id=autofocuswithoutkeyboarddialog data-description="Autofocus takes precedence over keyboard-focusable requirement.">
<button>keyboard focusable button</button>
<button tabindex="-1" autofocus class=target>mouse focusable autofocus button</button>
</dialog>

<dialog id=subtree data-description="Only keyboard-focusable elements should get dialog initial focus including in subtrees.">
<div>
<button tabindex="-1">mouse focusable button</button>
<button class=target>keyboard focusable button</button>
</div>
</dialog>

<dialog id=nestedbuttons data-description="Only keyboard-focusable elements should get dialog initial focus including in nested buttons.">
<button tabindex="-1">
<span>mouse focusable button</span>
<button tabindex="-1">nested mouse focusable button</button>
</button>
<button class=target>keyboard focusable button</button>
</dialog>

<script>
document.querySelectorAll('dialog').forEach(dialog => {
test(t => {
const target = dialog.querySelector('.target');
t.add_cleanup
t.add_cleanup(() => {
if (dialog.open)
dialog.close();
});

dialog.showModal();
assert_equals(document.activeElement,
dialog.hasAttribute('autofocus') ? dialog : target,
'showModal: the target element did not receive initial focus.');
dialog.close();

dialog.show();
assert_equals(document.activeElement, target, 'show: the target element did not receive initial focus.');
dialog.close();
}, dialog.dataset.description);
});
</script>
Loading