-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathfocus-within-toplayer-001.html
More file actions
83 lines (70 loc) · 3.17 KB
/
focus-within-toplayer-001.html
File metadata and controls
83 lines (70 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE html>
<meta charset="utf-8">
<title>Selectors: :focus-within should not propagate past top layer elements</title>
<link rel="help" href="https://drafts.csswg.org/selectors/#the-focus-within-pseudo">
<link rel="help" href="https://drafts.csswg.org/css-position-4/#top-layer">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
dialog::backdrop {
background: transparent;
}
</style>
<div id="outer">
<dialog id="dialog">
<input id="dialogInput">
</dialog>
</div>
<div id="popoverOuter">
<div id="popover" popover>
<input id="popoverInput">
</div>
</div>
<div id="nestOuter">
<dialog id="nestDialog">
<div id="nestPopover" popover>
<input id="nestInput">
</div>
</dialog>
</div>
<script>
test(t => {
const dialog = document.getElementById('dialog');
dialog.showModal();
t.add_cleanup(() => dialog.close());
const dialogInput = document.getElementById('dialogInput');
const outer = document.getElementById('outer');
dialogInput.focus();
assert_true(dialogInput.matches(':focus'), 'input should be focused');
assert_true(dialog.matches(':focus-within'), 'dialog (top layer) should match :focus-within');
assert_false(outer.matches(':focus-within'), 'ancestor outside top layer should not match :focus-within');
assert_false(document.body.matches(':focus-within'), 'body should not match :focus-within');
}, 'Focusing inside a modal dialog should not propagate :focus-within beyond the dialog.');
test(t => {
const popover = document.getElementById('popover');
popover.showPopover();
t.add_cleanup(() => popover.hidePopover());
const popoverInput = document.getElementById('popoverInput');
const popoverOuter = document.getElementById('popoverOuter');
popoverInput.focus();
assert_true(popoverInput.matches(':focus'), 'input should be focused');
assert_true(popover.matches(':focus-within'), 'popover (top layer) should match :focus-within');
assert_false(popoverOuter.matches(':focus-within'), 'ancestor outside top layer should not match :focus-within');
assert_false(document.body.matches(':focus-within'), 'body should not match :focus-within');
}, 'Focusing inside a popover should not propagate :focus-within beyond the popover.');
test(t => {
const nestDialog = document.getElementById('nestDialog');
nestDialog.showModal();
t.add_cleanup(() => nestDialog.close());
const nestPopover = document.getElementById('nestPopover');
nestPopover.showPopover();
t.add_cleanup(() => nestPopover.hidePopover());
const nestInput = document.getElementById('nestInput');
const nestOuter = document.getElementById('nestOuter');
nestInput.focus();
assert_true(nestInput.matches(':focus'), 'input should be focused');
assert_true(nestPopover.matches(':focus-within'), 'popover (innermost top layer) should match :focus-within');
assert_false(nestDialog.matches(':focus-within'), 'dialog (outer top layer) should not match :focus-within');
assert_false(nestOuter.matches(':focus-within'), 'ancestor outside both top layers should not match :focus-within');
}, 'With nested top layer elements, :focus-within should stop at the innermost top layer boundary.');
</script>