Skip to content

no-static-element-interactions

Static HTML elements do not have semantic meaning. This is clear in the case of <div> and <span>. It is less so clear in the case of elements that seem semantic, but that do not have a semantic mapping in the accessibility layer. For example <a>, <big>, <blockquote>, <footer>, <picture>, <strike> and <time> -- to name a few -- have no semantic layer mapping. They are as void of meaning as <div>.

The WAI-ARIA role attribute confers a semantic mapping to an element. The semantic value can then be expressed to a user via assistive technology.

In order to add interactivity such as a mouse or key event listener to a static element, that element must be given a role value as well.

🟢 How to resolve

Indicate the element's role with the role attribute:

vue
<template>
  <div
    @click="onClickHandler"
    @keypress="onKeyPressHandler"
    role="button"
    tabIndex="0"
  >
    Save
  </div>
</template>

Common interactive roles include:

  • button
  • link
  • checkbox
  • menuitem
  • menuitemcheckbox
  • menuitemradio
  • option
  • radio
  • searchbox
  • switch
  • textbox

Note: Adding a role to your element does not add behavior. When a semantic HTML element like <button> is used, then it will also respond to Enter key presses when it has focus. The developer is responsible for providing the expected behavior of an element that the role suggests it would have: focusability and key press support.

Do not use the role presentation on the element: it removes the element's semantics, and may also remove its children's semantics, creating big issues with assistive technology.

Adjust the list of handler prop names in the handlers array to increase or decrease the coverage surface of this rule in your codebase.

✔ Succeed

vue
<template>
  <button @click="() => {}" class="foo" />
  <div class="foo" @click="() => {}" role="button" />
  <input type="text" @click="() => {}" />
</template>

❌ Fail

vue
<template>
  <div @click="() => {}" />
</template>

📚 Resources