-
Notifications
You must be signed in to change notification settings - Fork 186
/
Copy path_KeyNavContainer.html
227 lines (180 loc) · 6.36 KB
/
_KeyNavContainer.html
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>_KeyNavContainer</title>
<script src="boilerplate.js"></script>
<script type="text/javascript">
require([
"doh/runner",
"dojo/_base/declare", "dojo/dom", "dojo/keys", "dojo/on", "dojo/parser",
"dijit/a11y", "dijit/focus", "dijit/registry",
"dijit/_WidgetBase", "dijit/_KeyNavContainer",
"dijit/tests/helpers", "dojo/domReady!"
], function(doh, declare, dom, keys, on, parser, a11y, focus, registry, _WidgetBase, _KeyNavContainer, helpers){
declare("TestContainer", [_WidgetBase, _KeyNavContainer], {
postCreate: function(){
this.inherited(arguments);
this.connectKeyNavHandlers([keys.LEFT_ARROW, keys.UP_ARROW], [keys.RIGHT_ARROW, keys.DOWN_ARROW]);
}
});
declare("TestContained", _WidgetBase, {
// _KeyNavContainer requires children to have focus()
focus: function(){
this.domNode.focus();
}
});
declare("TestNotFocusedChildContainer", [_WidgetBase, _KeyNavContainer], {
// Some container may override focus and have 'focusedChild==null'
// dijit/form/Select is a sample
focus: function(){
this.domNode.focus();
}
});
doh.register("parse", function(){
parser.parse();
});
/*
* Most of _KeyNavContainer is tested indirectly via Menu, Toolbar, etc. test suites, but
* starting to build up some basic tests here.
*/
doh.register("basic", [
{
name: "initial",
runTest: function(){
var c = registry.byId("container");
// initially container has tabIndex of 0
doh.is(0, c.domNode.getAttribute("tabIndex"), "container tabIndex=0");
// and all the contents have tabIndex of -1, or no tab index
doh.f(a11y.isTabNavigable("zero"), "child not tab navigable");
}
},
{
name: "tab in",
runTest: function(t){
var d = new doh.Deferred();
var c = registry.byId("container");
// focusing container (simulated tabbing into container) should move focus to first child
c.focus();
setTimeout(d.getTestCallback(function(){
doh.is("zero", focus.curNode.id, "focus moved to first child");
doh.t(a11y.isTabNavigable("zero"), "child is tab navigable");
doh.isNot(0, c.domNode.getAttribute("tabIndex"), "container tabIndex removed or set to -1");
}), 0);
return d;
}
},
{
name: "next",
runTest: function(t){
var d = new doh.Deferred();
var c = registry.byId("container");
on.emit(c.domNode, "keydown", {keyCode: keys.DOWN_ARROW, bubbles: true, cancelable: true});
setTimeout(d.getTestCallback(function(){
doh.is("one", focus.curNode.id, "focus moved to second child");
doh.f(a11y.isTabNavigable("zero"), "zero not tab navigable");
doh.t(a11y.isTabNavigable("one"), "one tab navigable");
}), 0);
return d;
}
},
{
name: "previous",
runTest: function(t){
var d = new doh.Deferred();
var c = registry.byId("container");
on.emit(c.domNode, "keydown", {keyCode: keys.LEFT_ARROW, bubbles: true, cancelable: true});
setTimeout(d.getTestCallback(function(){
doh.is("zero", focus.curNode.id, "focus moved to first child");
doh.f(a11y.isTabNavigable("one"), "one not tab navigable");
doh.t(a11y.isTabNavigable("zero"), "zero tab navigable");
}), 0);
return d;
}
},
{
name: "tab out",
runTest: function(t){
var d = new doh.Deferred();
var c = registry.byId("container");
dom.byId("input").focus();
// tab index on container restored
setTimeout(d.getTestCallback(function(){
doh.f(a11y.isTabNavigable("zero"), "child not tab navigable");
doh.is(0, c.domNode.getAttribute("tabIndex"), "container tabIndex restored");
}), 0);
return d;
}
},
{
name: "mouse in",
runTest: function(t){
var d = new doh.Deferred();
var c = registry.byId("container");
dom.byId("zero").focus();
// focusing first child directly (simulated mouse click) should remove tabIndex on container
setTimeout(d.getTestCallback(function(){
doh.isNot(0, c.domNode.getAttribute("tabIndex"), "container tabIndex removed or set to -1");
doh.t(a11y.isTabNavigable("zero"), "child tab navigable");
}), 0);
return d;
}
},
{
name: "search (& match) in container with not focused child",
runTest: function(t){
var d = new doh.Deferred();
var c = registry.byId("notFocusedChildContainer");
c.focus();
doh.is("notFocusedChildContainer", focus.curNode.id, "container is focused");
// searach with no match
on.emit(c.domNode, "keypress", {charCode: 115 /* "s" */, bubbles: true, cancelable: true});
setTimeout(d.getTestCallback(function(){
doh.is("single", focus.curNode.id, "focus changed to child 'single'");
}), 0);
return d;
}
},
{
name: "search (& no match) in container with not focused child",
setUp: function() {
var d = this.d = new doh.Deferred();
window.onerror = function(msg){
d.reject(new Error(msg));
};
},
runTest: function(t){
var d = this.d;
var c = registry.byId("notFocusedChildContainer");
c.focus();
doh.is("notFocusedChildContainer", focus.curNode.id, "container is focused");
// searach with no match
on.emit(c.domNode, "keypress", {charCode: 97 /* "a" */, bubbles: true, cancelable: true});
setTimeout(d.getTestCallback(function(){
doh.is("notFocusedChildContainer", focus.curNode.id, "focus not changed");
}), 0);
return d;
},
tearDown: function(){
window.onerror = null;
}
}
]);
doh.run();
});
</script>
</head>
<body>
<label for="input">before:</label><input id="input"/>
<div id="container" data-dojo-type="TestContainer">
<!-- comment just to make sure that numbering isn't thrown off -->
<div id="zero" data-dojo-type="TestContained">zero</div>
<div id="one" data-dojo-type="TestContained">one</div>
<div id="two" data-dojo-type="TestContained">two</div>
<div id="three" data-dojo-type="TestContained">three</div>
</div>
<div id="notFocusedChildContainer" data-dojo-type="TestNotFocusedChildContainer">
<div id="single" data-dojo-type="TestContained">single</div>
</div>
</body>
</html>