-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodal-dialog-empty.html
More file actions
139 lines (116 loc) · 3.46 KB
/
Copy pathmodal-dialog-empty.html
File metadata and controls
139 lines (116 loc) · 3.46 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AccessU Accessible JavaScript</title>
<style>
body { font-family: Arial, sans-serif; margin: 0; padding: 20px; font-size:1.2em;}
#legacyDialog{
height:300px;
width:300px;
position:absolute;
top:200px;
left:40%;
background:lightgrey;
display:none;
}
</style>
</head>
<body>
<h1>Modal Dialog test</h1>
<!-- Non-HTML dialog (legacy) -->
<button id="legacyOpen">Open the legacy dialog</button>
<div id="legacyDialog">
<p>This is a legacy modal Dialog</p>
<form>
<label>Input 1
<input type="text">
</label>
<fieldset>
<label>
<input type="checkbox">
Check 1
</label>
<label>
<input type="checkbox">
Check 2
</label>
<label>
<input type="checkbox">
Check 3
</label>
</fieldset>
<button type="submit">Submit</button>
</form>
<button id="legacyClose">Close</button>
</div>
<!-- HTML Dialog open button -->
<button id="htmlOpen">Open the HTML dialog</button>
<!-- HTML Dialog element -->
<dialog id="htmlDialog">
<p>This is an HTML modal Dialog</p>
<form>
<label>Input 1
<input type="text">
</label>
<fieldset>
<label>
<input type="checkbox">
Check 1
</label>
<label>
<input type="checkbox">
Check 2
</label>
<label>
<input type="checkbox">
Check 3
</label>
</fieldset>
<button type="submit">Submit</button>
</form>
<button id="htmlClose">Close</button>
</dialog>
<script>
// Legacy dialog implementation
const legacyOpen = document.getElementById("legacyOpen");
const legacyDialog = document.getElementById("legacyDialog");
let returnEl;
// Write an event listener for legacyOpen.
// Show the dialog.
// Set the returnEl.
// Initiate the keyboardTrap
// Write an event listener for legacyClose
// hide legacyDialog
// set focus on the returnEl
// Write a function to trap keyboard focus inside the modal
function keyboardTrap(activeEl){
// spacing in attribute selector needs to match HTML exactly.
const allElements = "button:not([style='display:none;']), [href], input, select, textarea, [tabindex]:not([tabindex='1'])";
// Get an array of allElements
// What's the first element? Store to a variable
// What's the last element? Store to a variable
firstModalEl.focus();
document.addEventListener("keydown", function(){
if(event.keyCode == 9){
if(document.activeElement === firstModalEl && event.shiftKey){
// ???
}
if(document.activeElement === lastModalEl && !event.shiftKey) {
// ???
}
}
})
}
// Add an event listener for escape key and close modal, return focus to launch button
// HTML dialog!
// built in keyboard trap and escape key
const htmlDialog = document.getElementById("htmlDialog");
const htmlOpen = document.getElementById("htmlOpen");
const htmlClose = document.getElementById("htmlClose");
// Add an eventlistener for htmlOpen
// Add an event listener for htmlClose
</script>
</body>
</html>