You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/docs/05-misc/02-accessibility-warnings.md
+35-6Lines changed: 35 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -4,14 +4,23 @@ title: 'Accessibility warnings'
4
4
5
5
Accessibility (shortened to a11y) isn't always easy to get right, but Svelte will help by warning you at compile time if you write inaccessible markup. However, keep in mind that many accessibility issues can only be identified at runtime using other automated tools and by manually testing your application.
6
6
7
+
Some warnings may be incorrect in your concrete use case. You can disable such false positives by placing a `<!-- svelte-ignore a11y-<code> -->` comment above the line that causes the warning. Example:
8
+
9
+
```svelte
10
+
<!-- svelte-ignore a11y-autofocus -->
11
+
<input autofocus />
12
+
```
13
+
7
14
Here is a list of accessibility checks Svelte will do for you.
8
15
9
16
## `a11y-accesskey`
10
17
11
18
Enforce no `accesskey` on element. Access keys are HTML attributes that allow web developers to assign keyboard shortcuts to elements. Inconsistencies between keyboard shortcuts and keyboard commands used by screen reader and keyboard-only users create accessibility complications. To avoid complications, access keys should not be used.
12
19
20
+
<!-- prettier-ignore -->
13
21
```svelte
14
-
<!-- A11y: Avoid using accesskey --><div accessKey="z" />
22
+
<!-- A11y: Avoid using accesskey -->
23
+
<div accessKey="z" />
15
24
```
16
25
17
26
## `a11y-aria-activedescendant-has-tabindex`
@@ -69,8 +78,10 @@ The following elements are visually distracting: `<marquee>` and `<blink>`.
69
78
70
79
Certain DOM elements are useful for screen reader navigation and should not be hidden.
71
80
81
+
<!-- prettier-ignore -->
72
82
```svelte
73
-
<!-- A11y: <h2> element should not be hidden --><h2 aria-hidden="true">invisible header</h2>
83
+
<!-- A11y: <h2> element should not be hidden -->
84
+
<h2 aria-hidden="true">invisible header</h2>
74
85
```
75
86
76
87
## `a11y-img-redundant-alt`
@@ -170,8 +181,10 @@ Certain reserved DOM elements do not support ARIA roles, states and properties.
170
181
171
182
The scope attribute should only be used on `<th>` elements.
172
183
184
+
<!-- prettier-ignore -->
173
185
```svelte
174
-
<!-- A11y: The scope attribute should only be used with <th> elements --><div scope="row" />
186
+
<!-- A11y: The scope attribute should only be used with <th> elements -->
187
+
<div scope="row" />
175
188
```
176
189
177
190
## `a11y-missing-attribute`
@@ -267,16 +280,30 @@ A non-interactive element does not support event handlers (mouse and key handler
267
280
268
281
Tab key navigation should be limited to elements on the page that can be interacted with.
269
282
283
+
<!-- prettier-ignore -->
284
+
```svelte
285
+
<!-- A11y: noninteractive element cannot have nonnegative tabIndex value -->
286
+
<div tabindex="0" />
287
+
```
288
+
289
+
## a11y-no-static-element-interactions
290
+
291
+
Elements like `<div>` with interactive handlers like `click` must have an ARIA role.
292
+
293
+
<!-- prettier-ignore -->
270
294
```svelte
271
-
<!-- A11y: noninteractive element cannot have nonnegative tabIndex value --><div tabindex="0" />
295
+
<!-- A11y: <div> with click handler must have an ARIA role -->
296
+
<div on:click={() => ''} />
272
297
```
273
298
274
299
## `a11y-positive-tabindex`
275
300
276
301
Avoid positive `tabindex` property values. This will move elements out of the expected tab order, creating a confusing experience for keyboard users.
277
302
303
+
<!-- prettier-ignore -->
278
304
```svelte
279
-
<!-- A11y: avoid tabindex values above zero --><div tabindex="1" />
305
+
<!-- A11y: avoid tabindex values above zero -->
306
+
<div tabindex="1" />
280
307
```
281
308
282
309
## `a11y-role-has-required-aria-props`
@@ -324,6 +351,8 @@ Enforce that only known ARIA attributes are used. This is based on the [WAI-ARIA
324
351
325
352
Elements with ARIA roles must use a valid, non-abstract ARIA role. A reference to role definitions can be found at [WAI-ARIA](https://www.w3.org/TR/wai-aria/#role_definitions) site.
326
353
354
+
<!-- prettier-ignore -->
327
355
```svelte
328
-
<!-- A11y: Unknown role 'toooltip' (did you mean 'tooltip'?) --><div role="toooltip" />
356
+
<!-- A11y: Unknown role 'toooltip' (did you mean 'tooltip'?) -->
0 commit comments