You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

no-interactive-element-to-noninteractive-role.md 2.3 KiB

пре 3 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # no-interactive-element-to-noninteractive-role
  2. Interactive HTML elements indicate _controls_ in the user interface. Interactive elements include `<a href>`, `<button>`, `<input>`, `<select>`, `<textarea>`.
  3. Non-interactive HTML elements and non-interactive ARIA roles indicate _content_ and _containers_ in the user interface. Non-interactive elements include `<main>`, `<area>`, `<h1>` (,`<h2>`, etc), `<img>`, `<li>`, `<ul>` and `<ol>`.
  4. [WAI-ARIA roles](https://www.w3.org/TR/wai-aria-1.1/#usage_intro) should not be used to convert an interactive element to a non-interactive element. Non-interactive ARIA roles include `article`, `banner`, `complementary`, `img`, `listitem`, `main`, `region` and `tooltip`.
  5. ## How do I resolve this error?
  6. ### Case: The element should be a container, like an article
  7. Wrap your interactive element in a `<div>` with the desired role.
  8. ```
  9. <div role="article">
  10. <button>Save</button>
  11. </div>
  12. ```
  13. ### Case: The element should be content, like an image
  14. Put the content inside your interactive element.
  15. ```
  16. <div
  17. role="button"
  18. onClick={() => {}}
  19. onKeyPress={() => {}}
  20. tabIndex="0">
  21. <div role="img" aria-label="Save" />
  22. </div>
  23. ```
  24. ### References
  25. 1. [WAI-ARIA roles](https://www.w3.org/TR/wai-aria-1.1/#usage_intro)
  26. 1. [WAI-ARIA Authoring Practices Guide - Design Patterns and Widgets](https://www.w3.org/TR/wai-aria-practices-1.1/#aria_ex)
  27. 1. [Fundamental Keyboard Navigation Conventions](https://www.w3.org/TR/wai-aria-practices-1.1/#kbd_generalnav)
  28. 1. [Mozilla Developer Network - ARIA Techniques](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_button_role#Keyboard_and_focus)
  29. ## Rule details
  30. The recommended options for this rule allow the `tr` element to be given a role of `presentation` (or its semantic equivalent `none`). Under normal circumstances, an element with an interactive role should not be semantically neutralized with `presentation` (or `none`).
  31. Options are provided as an object keyed by HTML element name; the value is an array of interactive roles that are allowed on the specified element.
  32. ```
  33. {
  34. 'no-interactive-element-to-noninteractive-role': [
  35. 'error',
  36. {
  37. tr: ['none', 'presentation'],
  38. },
  39. ]
  40. }
  41. ```
  42. Under the recommended options, the following code is valid. It would be invalid under the strict rules.
  43. ```
  44. <tr role="presentation" />
  45. ```