diff --git a/site/content/docs/05-accessibility-warnings.md b/site/content/docs/05-accessibility-warnings.md new file mode 100644 index 0000000000..3151ef259d --- /dev/null +++ b/site/content/docs/05-accessibility-warnings.md @@ -0,0 +1,255 @@ +--- +title: Accessibility warnings +--- + +Accessibility (shortened to a11y) isn't always easy to get right, but Svelte will help by warning you if you write inaccessible markup. + +Here is a list of accessibility checks Svelte will do it for you. + +--- + +### `a11y-accesskey` + +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 screenreader and keyboard only users create accessibility complications so to avoid complications, access keys should not be used. + +```sv + +
+``` + +--- + +### `a11y-aria-attributes` + +Certain reserved DOM elements do not support ARIA roles, states and properties. This is often because they are not visible, for example `meta`, `html`, `script`, `style`. This rule enforces that these DOM elements do not contain the `aria-*` props. + +```sv + + +``` + +--- + +### `a11y-autofocus` + +Enforce that `autofocus` is not used on elements. Autofocusing elements can cause usability issues for sighted and non-sighted users, alike. + +```sv + + +``` + +--- + +### `a11y-distracting-elements` + +Enforces that no distracting elements are used. Elements that can be visually distracting can cause accessibility issues with visually impaired users. Such elements are most likely deprecated, and should be avoided. + +The following elements are visually distracting: `` and ``. + +```sv + + +``` + +--- + +### `a11y-hidden` + +Certain DOM elements are useful for screen readers navigation and should not be hidden. + +```sv + +

invisible header

+``` + +--- + +### `a11y-img-redundant-alt` + +Enforce img alt attribute does not contain the word image, picture, or photo. Screenreaders already announce `img` elements as an image. There is no need to use words such as _image_, _photo_, and/or _picture_. + +```sv +Foo eating a sandwich. + + +Picture of me taking a photo of an image + + +Photo of foo being weird. + + +Image of me at a bar! + + +Picture of baz fixing a bug. +``` + +--- + +### `a11y-invalid-attribute` + +Enforce that accessibility attribute should have valid value + +```sv + +invalid +``` + +--- + +### `a11y-label-has-associated-control` + +Enforce that a label tag has a text label and an associated control. + +There are two supported ways to associate a label with a control: + +- Wrapping a control in a label tag. +- Adding `for` to a label and assigning it a DOM ID string that indicates an input on the page. + +```sv + + + + + + +``` + +--- + +### `a11y-media-has-caption` + +Providing captions for media is essential for deaf users to follow along. Captions should be a transcription or translation of the dialogue, sound effects, relevant musical cues, and other relevant audio information. Not only is this important for accessibility, but can also be useful for all users in the case that the media is unavailable (similar to `alt` text on an image when an image is unable to load). + +The captions should contain all important and relevant information to understand the corresponding media. This may mean that the captions are not a 1:1 mapping of the dialogue in the media content. However, captions are not necessary for video components with the `muted` attribute. + +```sv + + + + + + + + + +``` + +--- + +### `a11y-misplaced-role` + +Certain reserved DOM elements do not support ARIA roles, states and properties. This is often because they are not visible, for example `meta`, `html`, `script`, `style`. This rule enforces that these DOM elements do not contain the `role` props. + +```sv + + +``` + +--- + +### `a11y-misplaced-scope` + +The scope scope should be used only on `` elements. + +```sv + +
+``` + +--- + +### `a11y-missing-attribute` + +Enforce that element should have required accessibility attribute + +```sv + + + + + + + +text +``` + +--- + +### `a11y-missing-content` + +Enforce that heading elements (`h1`, `h2`, etc.) and anchors have content and that the content is accessible to screen readers + +```sv + + + + +

+``` + +--- + +### `a11y-no-onchange` + +Enforce usage of `on:blur` over/in parallel with `on:change` on select menu elements for accessibility. `on:blur` should be used instead of `on:change`, unless absolutely necessary and it causes no negative consequences for keyboard only or screen reader users. `on:blur` is a more declarative action by the user: for instance in a dropdown, using the arrow keys to toggle between options will trigger the `on:change` event in some browsers. Regardless, when a change of context results from an `on:blur` event or an `on:change` event, the user should be notified of the change unless it occurs below the currently focused element. + +```sv + + + + +``` + +--- + +### `a11y-positive-tabindex` + +Avoid positive `tabIndex` property values to synchronize the flow of the page with keyboard tab order. + +```sv + +
+``` + +--- + +### `a11y-structure` + +Warns when accessibility related elements are not in a right structure. + +```sv + +
+
Image caption
+
+``` + +--- + +### `a11y-unknown-aria-attribute` + +Invalid aria attribute. Enforces valid `aria-*` property based on [WAI-ARIA States and Properties spec](https://www.w3.org/WAI/PF/aria-1.1/states_and_properties) + +```sv + + +``` + +--- + +### `a11y-unknown-role` + +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. + +```sv + +
+```