-
-
Notifications
You must be signed in to change notification settings - Fork 208
/
cases.ts
290 lines (267 loc) · 9.17 KB
/
cases.ts
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
import { convertAnnotatedSourceToFailureCase } from '@angular-eslint/utils';
import type { MessageIds } from '../../../src/rules/accessibility-interactive-supports-focus';
const messageId: MessageIds = 'interactiveSupportsFocus';
export const valid = [
// no interactive outputs
{ code: '<div></div>' },
// aria-hidden
{
code: `
<div aria-hidden (click)="onClick()"></div>
<div aria-hidden="true" (click)="onClick()"></div>
<div [attr.aria-hidden]="true" (click)="onClick()"></div>
`,
},
// aria-disabled
{
code: `
<div role="button" aria-disabled="true" (click)="onClick()"></div>
<div role="button" [attr.aria-disabled]="true" (click)="onClick()"></div>
`,
},
// presentation role
{
code: `
<div role="presentation" (click)="onClick()"></div>
<div role="none" (click)="onClick()"></div>
`,
},
// explicitly assigned not interactive role
{
code: `
<div role="progressbar" (click)="onClick()"></div>
<div role="region" (click)="onClick()"></div>
`,
},
// hidden input is not interactive, tabindex is not required
{
code: `
<input type="hidden" (click)="onClick()">
<input type="hidden" (click)="onClick()" tabindex="-1">
<input type="hidden" (click)="onClick()" [attr.tabindex]="-1">
`,
},
// interactive elements
{
code: `
<input type="text" (keyup)="onKeyUp()">
<input (keydown)="onKeydown()">
<input (click)="onClick()" role="combobox">
<button (click)="onClick()" class="foo">Foo</button>
<option (click)="onClick()" class="foo">Food</option>
<select (click)="onClick()" class="foo"></select>
<summary (click)="onClick()">Foo</summary>
<textarea (keypress)="onKeypress()" class="foo"></textarea>
`,
},
// disabled
{
code: `
<input disabled type="text" (click)="onClick()">
<button disabled (click)="onClick()" class="foo">Foo</button>
<select disabled (click)="onClick()" class="foo"></select>
`,
},
// area without href needs tabindex for focus
{
code: `
<area href="#" (click)="onClick()" class="foo"/>
<area (click)="onClick()" tabindex=0 class="foo"/>
`,
},
// a without href needs tabindex for focus
{
code: `
<a (click)="onClick()" tabindex="0">Click me</a>
<a (click)="onClick()" [attr.tabindex]="0">Click me</a>',
<a (click)="onClick()" tabindex="bad">Click me</a>',
<a (click)="onClick()" [attr.tabindex]="undefined"}>Click me</a>',
<a (click)="onClick()" [attr.tabindex]="dynamicTabindex">Click me</a>',
`,
},
// interactive role with href and click
{ code: '<a role="button" (click)="onClick()" href="#">hash</a>' },
// href and click
{
code: `
<a (click)="onClick()" href="http://x.y.z">x.y.z</a>
<a role="link" (click)="onClick()" href="http://x.y.z">x.y.z</a>
<a (click)="onClick()" href="javascript:void(0);">Click ALL the things!</a>
`,
},
// click and tabindex (focusable but generally not recommended)
{
code: `
<a (click)="onClick()" tabindex="0">x.y.z</a>
<a (click)="onClick()" tabindex={0}>x.y.z</a>
`,
},
// routerLink
{
code: `
<a routerLink="route" (click)="onClick()"></a>
<a [routerLink]="route" (click)="onClick()"></a>
`,
},
// invalid tabindex
{
code: `
<div (click)="onClick()" tabindex="invalid"></div>
<div (click)="onClick()" [attr.tabindex]="undefined"></div>
<span (click)="onClick()" [attr.tabindex]=="false">Submit</span>
<span (click)="onClick()" [attr.tabindex]=="null">Submit</span>
`,
},
// valid tabindex
{
code: `
<span (click)="onClick()" tabindex="0">Click me!</span>
<span (click)="onClick()" [attr.tabindex]="0">Click me!</span>
<span (click)="onClick()" tabindex="-1">Click me!</span>
<span (click)="onClick()" [attr.tabindex]="-1">Click me!</span>
`,
},
// interactive role with tabindex
{
code: `
<div role="button" tabindex="0" (click)="onClick()"></div>
<div role="checkbox" tabindex="0" (click)="onClick()"></div>
<div role="link" tabindex="0" (click)="onClick()"></div>
<div role="menuitem" tabindex="0" (click)="onClick()"></div>
<div role="checkbox" tabindex="0" (click)="onClick()"></div>
<div role="menuitem" tabindex="0" (click)="onClick()"></div>
<div role="option" tabindex="0" (click)="onClick()"></div>
<div role="radio" tabindex="0" (click)="onClick()"></div>
<div role="spinbutton" tabindex="0" (click)="onClick()"></div>
<div role="switch" tabindex="0" (click)="onClick()"></div>
<div role="tablist" tabindex="0" (click)="onClick()"></div>
<div role="tab" tabindex="0" (click)="onClick()"></div>
<div role="textbox" tabindex="0" (click)="onClick()"></div>
`,
},
// elements with contenteditable enabled are interactive by default
{
code: `
<div contenteditable="true" (keyup)="onKeyUp()">Edit this text</div>
<div [attr.contenteditable]="true" (keydown)="onKeyDown()">Edit this text</div>
<div contenteditable (keypress)="onKeyPress()">Edit this too!</div>
`,
},
];
export const invalid = [
// aria-hidden="false"
convertAnnotatedSourceToFailureCase({
description: 'should fail not hidden from screen reader',
annotatedSource: `
<div aria-hidden="false" (click)="onClick()"></div>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`,
messageId,
}),
convertAnnotatedSourceToFailureCase({
description:
'should fail not hidden from screen reader with bound aria-hidden attribute',
annotatedSource: `
<div [attr.aria-hidden]="false" (click)="onClick()"></div>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`,
messageId,
}),
// aria-disabled="false"
convertAnnotatedSourceToFailureCase({
description: 'should fail aria-disabled is false',
annotatedSource: `
<div role="button" aria-disabled="false" (click)="onClick()"></div>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`,
messageId,
}),
convertAnnotatedSourceToFailureCase({
description: 'should fail aria-disabled is false with bound attribute',
annotatedSource: `
<div [attr.aria-disabled]="false" (click)="onClick()"></div>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`,
messageId,
}),
// interactive role, non interactive element
convertAnnotatedSourceToFailureCase({
description:
'should fail interactive role but element does not support focus',
annotatedSource: `
<div role="button" (click)="onClick()"></div>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`,
messageId,
}),
// no role, non interactive element
convertAnnotatedSourceToFailureCase({
description: 'should fail non-interactive element does not support focus',
annotatedSource: `
<span (click)="onClick()">Submit</span>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`,
messageId,
}),
convertAnnotatedSourceToFailureCase({
description:
'should fail non-interactive element with aria-label does not support focus',
annotatedSource: `
<div (click)="onClick()" [attr.aria-label]="clickableThing"></div>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`,
messageId,
}),
// invalid role, non interactive element
convertAnnotatedSourceToFailureCase({
description:
'should fail non-interactive element with invalid role does not support focus',
annotatedSource: `
<div (click)="onClick()" role="invalid"></div>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`,
messageId,
data: {
role: 'invalid',
},
}),
// area and a are not interactive without href
convertAnnotatedSourceToFailureCase({
description:
'should fail non-interactive element does not support focus, area should have href',
annotatedSource: `
<area (click)="onClick()" class="foo">
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`,
messageId,
}),
convertAnnotatedSourceToFailureCase({
description:
'should fail non-interactive element does not support focus, anchor should have href',
annotatedSource: `
<a (click)="onClick()">Click me</a>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`,
messageId,
}),
// non-interactive element with keyup, keydown, keypress interaction handlers
convertAnnotatedSourceToFailureCase({
description:
'should fail non-interactive element with key event does not support focus',
annotatedSource: `
<div (keyup)="onKeyUp()" (keydown)="onKeyDown()" (keypress)="onKeyPress()">Cannot be focused</div>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`,
messageId,
}),
// contenteditable="false"
convertAnnotatedSourceToFailureCase({
description:
'should fail non-interactive element with contenteditable disabled does not support focus',
annotatedSource: `
<div [attr.contenteditable]="false" (keyup)="onKeyUp()">Cannot be focused</div>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`,
messageId,
}),
];