@@ -3,6 +3,21 @@ describe('dom.isNativelyFocusable', function () {
3
3
4
4
var fixture = document . getElementById ( 'fixture' ) ;
5
5
6
+ function hideByClipping ( el ) {
7
+ el . style . cssText = 'position: absolute !important;' +
8
+ ' clip: rect(0px 0px 0px 0px); /* IE6, IE7 */' +
9
+ ' clip: rect(0px, 0px, 0px, 0px);' ;
10
+ }
11
+
12
+ function hideByMovingOffScreen ( el ) {
13
+ el . style . cssText = 'position:absolute;' +
14
+ ' left:-10000px;' +
15
+ ' top:auto;' +
16
+ ' width:1px;' +
17
+ ' height:1px;' +
18
+ ' overflow:hidden;' ;
19
+ }
20
+
6
21
afterEach ( function ( ) {
7
22
document . getElementById ( 'fixture' ) . innerHTML = '' ;
8
23
} ) ;
@@ -72,14 +87,106 @@ describe('dom.isNativelyFocusable', function () {
72
87
73
88
} ) ;
74
89
75
- it ( 'should return false for non-visible elements' , function ( ) {
76
- fixture . innerHTML = '<input type="text" id="target" style="display: none">' ;
90
+ it ( 'should return false for elements hidden with display:none' , function ( ) {
91
+ fixture . innerHTML = '<button id="target" style="display: none">button</button>' ;
92
+ var el = document . getElementById ( 'target' ) ;
93
+
94
+ assert . isFalse ( axe . commons . dom . isNativelyFocusable ( el ) ) ;
95
+
96
+ } ) ;
97
+
98
+ it ( 'should return false for elements hidden with visibility:hidden' , function ( ) {
99
+ fixture . innerHTML = '<button id="target" style="visibility: hidden">button</button>' ;
100
+ var el = document . getElementById ( 'target' ) ;
101
+
102
+ assert . isFalse ( axe . commons . dom . isNativelyFocusable ( el ) ) ;
103
+
104
+ } ) ;
105
+
106
+ it ( 'should return true for clipped elements' , function ( ) {
107
+ fixture . innerHTML = '<button id="target">button</button>' ;
108
+ var el = document . getElementById ( 'target' ) ;
109
+ hideByClipping ( el ) ;
110
+
111
+ assert . isTrue ( axe . commons . dom . isNativelyFocusable ( el ) ) ;
112
+
113
+ } ) ;
114
+
115
+ it ( 'should return true for elements positioned off screen' , function ( ) {
116
+ fixture . innerHTML = '<button id="target">button</button>' ;
117
+ var el = document . getElementById ( 'target' ) ;
118
+ hideByMovingOffScreen ( el ) ;
119
+
120
+ assert . isTrue ( axe . commons . dom . isNativelyFocusable ( el ) ) ;
121
+
122
+ } ) ;
123
+
124
+ it ( 'should return false for elements hidden with display:none on an ancestor' , function ( ) {
125
+ fixture . innerHTML = '<div id="parent" style="display:none"><button id="target">button</button></div>' ;
126
+ var el = document . getElementById ( 'target' ) ;
127
+
128
+ assert . isFalse ( axe . commons . dom . isNativelyFocusable ( el ) ) ;
129
+
130
+ } ) ;
131
+
132
+ it ( 'should return false for elements hidden with visibility:hidden on an ancestor' , function ( ) {
133
+ fixture . innerHTML = '<div id="parent" style="visibility: hidden"><button id="target">button</button></div>' ;
77
134
var el = document . getElementById ( 'target' ) ;
78
135
79
136
assert . isFalse ( axe . commons . dom . isNativelyFocusable ( el ) ) ;
80
137
81
138
} ) ;
82
139
140
+ it ( 'should return true for elements with a clipped ancestor' , function ( ) {
141
+ fixture . innerHTML = '<div id="parent"><button id="target">button</button></div>' ;
142
+ hideByClipping ( document . getElementById ( 'parent' ) ) ;
143
+ var el = document . getElementById ( 'target' ) ;
144
+
145
+ assert . isTrue ( axe . commons . dom . isNativelyFocusable ( el ) ) ;
146
+
147
+ } ) ;
148
+
149
+ it ( 'should return true for elements off-screened by an ancestor' , function ( ) {
150
+ fixture . innerHTML = '<div id="parent"><button id="target">button</button></div>' ;
151
+ hideByMovingOffScreen ( document . getElementById ( 'parent' ) ) ;
152
+ var el = document . getElementById ( 'target' ) ;
153
+
154
+ assert . isTrue ( axe . commons . dom . isNativelyFocusable ( el ) ) ;
155
+
156
+ } ) ;
157
+
158
+ it ( 'should return false for hidden inputs with tabindex' , function ( ) {
159
+ fixture . innerHTML = '<input type="hidden" tabindex="1" id="target">' ;
160
+ var el = document . getElementById ( 'target' ) ;
161
+
162
+ assert . isFalse ( axe . commons . dom . isFocusable ( el ) ) ;
163
+
164
+ } ) ;
165
+
166
+ it ( 'should return false for disabled inputs with tabindex' , function ( ) {
167
+ fixture . innerHTML = '<input tabindex="1" id="target" disabled>' ;
168
+ var el = document . getElementById ( 'target' ) ;
169
+
170
+ assert . isFalse ( axe . commons . dom . isFocusable ( el ) ) ;
171
+
172
+ } ) ;
173
+
174
+ it ( 'should return false for hidden buttons with tabindex' , function ( ) {
175
+ fixture . innerHTML = '<button style="visibility:hidden" tabindex="0" id="target"></button>' ;
176
+ var el = document . getElementById ( 'target' ) ;
177
+
178
+ assert . isFalse ( axe . commons . dom . isFocusable ( el ) ) ;
179
+
180
+ } ) ;
181
+
182
+ it ( 'should return false for disabled buttons with tabindex' , function ( ) {
183
+ fixture . innerHTML = '<button tabindex="0" id="target" disabled></button>' ;
184
+ var el = document . getElementById ( 'target' ) ;
185
+
186
+ assert . isFalse ( axe . commons . dom . isFocusable ( el ) ) ;
187
+
188
+ } ) ;
189
+
83
190
it ( 'should return true for an anchor with an href' , function ( ) {
84
191
fixture . innerHTML = '<a href="something.html" id="target"></a>' ;
85
192
var el = document . getElementById ( 'target' ) ;
0 commit comments