Debian Codegraph @

dijit/tests/_KeyNavContainer.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4
5 <meta http-equiv="Content-type" content="text/html; charset=utf-8">
6
7 <title>_KeyNavContainer</title>
8
9 <script src="boilerplate.js"></script>
10
11 <script type="text/javascript">
12 require([
13 "doh/runner",
14 "dojo/_base/declare", "dojo/dom", "dojo/keys", "dojo/on", "dojo/parser",
15 "dijit/a11y", "dijit/focus", "dijit/registry",
16 "dijit/_WidgetBase", "dijit/_KeyNavContainer",
17 "dijit/tests/helpers", "dojo/domReady!"
18 ], function(doh, declare, dom, keys, on, parser, a11y, focus, registry, _WidgetBase, _KeyNavContainer, helpers){
19
20 declare("TestContainer", [_WidgetBase, _KeyNavContainer], {
21 postCreate: function(){
22 this.inherited(arguments);
23 this.connectKeyNavHandlers([keys.LEFT_ARROW, keys.UP_ARROW], [keys.RIGHT_ARROW, keys.DOWN_ARROW]);
24 }
25 });
26
27 declare("TestContained", _WidgetBase, {
28 // _KeyNavContainer requires children to have focus()
29 focus: function(){
30 this.domNode.focus();
31 }
32 });
33
34 declare("TestNotFocusedChildContainer", [_WidgetBase, _KeyNavContainer], {
35 // Some container may override focus and have 'focusedChild==null'
36 // dijit/form/Select is a sample
37 focus: function(){
38 this.domNode.focus();
39 }
40 });
41
42 doh.register("parse", function(){
43 parser.parse();
44 });
45
46
47 /*
48 * Most of _KeyNavContainer is tested indirectly via Menu, Toolbar, etc. test suites, but
49 * starting to build up some basic tests here.
50 */
51
52 doh.register("basic", [
53 {
54 name: "initial",
55 runTest: function(){
56 var c = registry.byId("container");
57
58 // initially container has tabIndex of 0
59 doh.is(0, c.domNode.getAttribute("tabIndex"), "container tabIndex=0");
60
61 // and all the contents have tabIndex of -1, or no tab index
62 doh.f(a11y.isTabNavigable("zero"), "child not tab navigable");
63 }
64 },
65 {
66 name: "tab in",
67 runTest: function(t){
68 var d = new doh.Deferred();
69
70 var c = registry.byId("container");
71
72 // focusing container (simulated tabbing into container) should move focus to first child
73 c.focus();
74
75 setTimeout(d.getTestCallback(function(){
76 doh.is("zero", focus.curNode.id, "focus moved to first child");
77 doh.t(a11y.isTabNavigable("zero"), "child is tab navigable");
78 doh.isNot(0, c.domNode.getAttribute("tabIndex"), "container tabIndex removed or set to -1");
79 }), 0);
80
81 return d;
82 }
83 },
84 {
85 name: "next",
86 runTest: function(t){
87 var d = new doh.Deferred();
88
89 var c = registry.byId("container");
90
91 on.emit(c.domNode, "keydown", {keyCode: keys.DOWN_ARROW, bubbles: true, cancelable: true});
92
93 setTimeout(d.getTestCallback(function(){
94 doh.is("one", focus.curNode.id, "focus moved to second child");
95 doh.f(a11y.isTabNavigable("zero"), "zero not tab navigable");
96 doh.t(a11y.isTabNavigable("one"), "one tab navigable");
97 }), 0);
98
99 return d;
100 }
101 },
102 {
103 name: "previous",
104 runTest: function(t){
105 var d = new doh.Deferred();
106
107 var c = registry.byId("container");
108
109 on.emit(c.domNode, "keydown", {keyCode: keys.LEFT_ARROW, bubbles: true, cancelable: true});
110
111 setTimeout(d.getTestCallback(function(){
112 doh.is("zero", focus.curNode.id, "focus moved to first child");
113 doh.f(a11y.isTabNavigable("one"), "one not tab navigable");
114 doh.t(a11y.isTabNavigable("zero"), "zero tab navigable");
115 }), 0);
116
117 return d;
118 }
119 },
120 {
121 name: "tab out",
122 runTest: function(t){
123 var d = new doh.Deferred();
124
125 var c = registry.byId("container");
126
127 dom.byId("input").focus();
128
129 // tab index on container restored
130 setTimeout(d.getTestCallback(function(){
131 doh.f(a11y.isTabNavigable("zero"), "child not tab navigable");
132 doh.is(0, c.domNode.getAttribute("tabIndex"), "container tabIndex restored");
133 }), 0);
134
135 return d;
136 }
137 },
138 {
139 name: "mouse in",
140 runTest: function(t){
141 var d = new doh.Deferred();
142
143 var c = registry.byId("container");
144
145 dom.byId("zero").focus();
146
147 // focusing first child directly (simulated mouse click) should remove tabIndex on container
148 setTimeout(d.getTestCallback(function(){
149 doh.isNot(0, c.domNode.getAttribute("tabIndex"), "container tabIndex removed or set to -1");
150 doh.t(a11y.isTabNavigable("zero"), "child tab navigable");
151 }), 0);
152
153 return d;
154 }
155 },
156 {
157 name: "search (& match) in container with not focused child",
158 runTest: function(t){
159 var d = new doh.Deferred();
160
161 var c = registry.byId("notFocusedChildContainer");
162 c.focus();
163
164 doh.is("notFocusedChildContainer", focus.curNode.id, "container is focused");
165
166 // searach with no match
167 on.emit(c.domNode, "keypress", {charCode: 115 /* "s" */, bubbles: true, cancelable: true});
168
169 setTimeout(d.getTestCallback(function(){
170 doh.is("single", focus.curNode.id, "focus changed to child 'single'");
171 }), 0);
172
173 return d;
174 }
175 },
176 {
177 name: "search (& no match) in container with not focused child",
178 setUp: function() {
179 var d = this.d = new doh.Deferred();
180 window.onerror = function(msg){
181 d.reject(new Error(msg));
182 };
183 },
184 runTest: function(t){
185 var d = this.d;
186
187 var c = registry.byId("notFocusedChildContainer");
188 c.focus();
189
190 doh.is("notFocusedChildContainer", focus.curNode.id, "container is focused");
191
192 // searach with no match
193 on.emit(c.domNode, "keypress", {charCode: 97 /* "a" */, bubbles: true, cancelable: true});
194
195 setTimeout(d.getTestCallback(function(){
196 doh.is("notFocusedChildContainer", focus.curNode.id, "focus not changed");
197 }), 0);
198
199 return d;
200 },
201 tearDown: function(){
202 window.onerror = null;
203 }
204 }
205 ]);
206
207 doh.run();
208 });
209
210 </script>
211 </head>
212 <body>
213
214 <label for="input">before:</label><input id="input"/>
215 <div id="container" data-dojo-type="TestContainer">
216 <!-- comment just to make sure that numbering isn't thrown off -->
217 <div id="zero" data-dojo-type="TestContained">zero</div>
218 <div id="one" data-dojo-type="TestContained">one</div>
219 <div id="two" data-dojo-type="TestContained">two</div>
220 <div id="three" data-dojo-type="TestContained">three</div>
221 </div>
222
223 <div id="notFocusedChildContainer" data-dojo-type="TestNotFocusedChildContainer">
224 <div id="single" data-dojo-type="TestContained">single</div>
225 </div>
226 </body>
227 </html>