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-noninteractive-element-to-interactive-role.md 2.4 KiB

пре 3 година
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # no-noninteractive-element-to-interactive-role
  2. Non-interactive HTML elements indicate _content_ and _containers_ in the user interface. Non-interactive elements include `<main>`, `<area>`, `<h1>` (,`<h2>`, etc), `<img>`, `<li>`, `<ul>` and `<ol>`.
  3. Interactive HTML elements indicate _controls_ in the user interface. Interactive elements include `<a href>`, `<button>`, `<input>`, `<select>`, `<textarea>`.
  4. [WAI-ARIA roles](https://www.w3.org/TR/wai-aria-1.1/#usage_intro) should not be used to convert a non-interactive element to an interactive element. Interactive ARIA roles include `button`, `link`, `checkbox`, `menuitem`, `menuitemcheckbox`, `menuitemradio`, `option`, `radio`, `searchbox`, `switch` and `textbox`.
  5. ## How do I resolve this error?
  6. ### Case: This element should be a control, like a button
  7. Put the control inside the non-interactive container element.
  8. ```
  9. <li>
  10. <div
  11. role="button"
  12. onClick={() => {}}
  13. onKeyPress={() => {}}>
  14. Save
  15. </div>
  16. </li>
  17. ```
  18. Or wrap the content inside your interactive element.
  19. ```
  20. <div
  21. role="button"
  22. onClick={() => {}}
  23. onKeyPress={() => {}}
  24. tabIndex="0">
  25. <img src="some/file.png" alt="Save" />
  26. </div>
  27. ```
  28. ### References
  29. 1. [WAI-ARIA roles](https://www.w3.org/TR/wai-aria-1.1/#usage_intro)
  30. 1. [WAI-ARIA Authoring Practices Guide - Design Patterns and Widgets](https://www.w3.org/TR/wai-aria-practices-1.1/#aria_ex)
  31. 1. [Fundamental Keyboard Navigation Conventions](https://www.w3.org/TR/wai-aria-practices-1.1/#kbd_generalnav)
  32. 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)
  33. ## Rule details
  34. The recommended options for this rule allow several common interactive roles to be applied to a non-interactive element. The 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.
  35. ```
  36. {
  37. 'no-noninteractive-element-to-interactive-role': [
  38. 'error',
  39. {
  40. ul: ['listbox', 'menu', 'menubar', 'radiogroup', 'tablist', 'tree', 'treegrid'],
  41. ol: ['listbox', 'menu', 'menubar', 'radiogroup', 'tablist', 'tree', 'treegrid'],
  42. li: ['menuitem', 'option', 'row', 'tab', 'treeitem'],
  43. table: ['grid'],
  44. td: ['gridcell'],
  45. },
  46. }
  47. ```
  48. Under the recommended options, the following code is valid. It would be invalid under the strict rules.
  49. ```
  50. <ul role="menu" />
  51. ```