Skip to content

Commit 1c7ed55

Browse files
committed
docs: add a11y-no-static-element-interactions
closes #8862
1 parent 00c806d commit 1c7ed55

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

documentation/docs/05-misc/02-accessibility-warnings.md

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,23 @@ title: 'Accessibility warnings'
44

55
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.
66

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+
714
Here is a list of accessibility checks Svelte will do for you.
815

916
## `a11y-accesskey`
1017

1118
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.
1219

20+
<!-- prettier-ignore -->
1321
```svelte
14-
<!-- A11y: Avoid using accesskey --><div accessKey="z" />
22+
<!-- A11y: Avoid using accesskey -->
23+
<div accessKey="z" />
1524
```
1625

1726
## `a11y-aria-activedescendant-has-tabindex`
@@ -69,8 +78,10 @@ The following elements are visually distracting: `<marquee>` and `<blink>`.
6978

7079
Certain DOM elements are useful for screen reader navigation and should not be hidden.
7180

81+
<!-- prettier-ignore -->
7282
```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>
7485
```
7586

7687
## `a11y-img-redundant-alt`
@@ -170,8 +181,10 @@ Certain reserved DOM elements do not support ARIA roles, states and properties.
170181

171182
The scope attribute should only be used on `<th>` elements.
172183

184+
<!-- prettier-ignore -->
173185
```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" />
175188
```
176189

177190
## `a11y-missing-attribute`
@@ -267,16 +280,30 @@ A non-interactive element does not support event handlers (mouse and key handler
267280

268281
Tab key navigation should be limited to elements on the page that can be interacted with.
269282

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 -->
270294
```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={() => ''} />
272297
```
273298

274299
## `a11y-positive-tabindex`
275300

276301
Avoid positive `tabindex` property values. This will move elements out of the expected tab order, creating a confusing experience for keyboard users.
277302

303+
<!-- prettier-ignore -->
278304
```svelte
279-
<!-- A11y: avoid tabindex values above zero --><div tabindex="1" />
305+
<!-- A11y: avoid tabindex values above zero -->
306+
<div tabindex="1" />
280307
```
281308

282309
## `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
324351

325352
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.
326353

354+
<!-- prettier-ignore -->
327355
```svelte
328-
<!-- A11y: Unknown role 'toooltip' (did you mean 'tooltip'?) --><div role="toooltip" />
356+
<!-- A11y: Unknown role 'toooltip' (did you mean 'tooltip'?) -->
357+
<div role="toooltip" />
329358
```

0 commit comments

Comments
 (0)