Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

eslint-plugin-a11y-experimental

Experimental accessibility rules for ESLint and Oxlint.

日本語版はこちら

Installation

pnpm add -D eslint-plugin-a11y-experimental

Usage

ESLint

In your configuration file, import the plugin and add it to the plugins key:

import { defineConfig } from "eslint/config";
import a11y from "eslint-plugin-a11y-experimental";

export default defineConfig([
  {
    plugins: {
      a11y,
    },
    rules: {
      "a11y/no-aria-label": "warn",
    },
  },
]);

Oxlint

Oxlint supports ESLint v9+ compatible plugins via the jsPlugins field in .oxlintrc.json:

{
  "jsPlugins": ["eslint-plugin-a11y-experimental"],
  "rules": {
    "eslint-plugin-a11y-experimental/no-aria-label": "warn"
  }
}

Rules

Rule Description
no-aria-label Disallow use of the aria-label attribute
no-conditional-aria-text Disallow conditional text content alongside aria-expanded, and conditional values on aria-label or configured props
aria-actions-require-interactive-role Require elements referenced by aria-actions to have an interactive ARIA role
focusgroup-valid-syntax Enforce valid focusgroup attribute values
focusgroup-require-focusable-children Require focusgroup elements to have at least one focusable descendant
valid-role-for-element Enforce that role is allowed on the HTML element according to ARIA in HTML

no-aria-label

The aria-label attribute overrides the accessible name computed from visible text, which can easily cause a mismatch between what sighted users see and what screen reader users hear. Use visible text alternatives instead.

// ❌ Bad
<button aria-label="Close">✕</button>

// ✅ Good
<button>
  <span aria-hidden="true">✕</span>
  <span className="sr-only">Close</span>
</button>

no-conditional-aria-text

Combining aria-expanded with conditionally changing text causes screen readers to announce both the state change and the text change, which is redundant and confusing.

// ❌ Bad: text changes while aria-expanded already conveys the state
<button aria-expanded={isOpen}>{isOpen ? "Close" : "Open"}</button>

// ✅ Good: keep the label static
<button aria-expanded={isOpen}>Menu</button>

// ❌ Bad: conditional value on aria-label is also disallowed
<button aria-label={isOpen ? "Close" : "Open"}>Menu</button>

Options

Use additionalProps to add extra prop names that should also be forbidden from having conditional values:

"a11y/no-conditional-aria-text": ["error", {
  additionalProps: ["alternativeText", "tooltipText"]
}]

aria-actions-require-interactive-role

The aria-actions attribute references elements that provide contextual actions for the current element (e.g. a context menu). Referenced elements must have an interactive ARIA role so that assistive technologies expose them correctly.

// ❌ Bad: referenced element has no interactive role
<button aria-actions="ctx">Options</button>
<div id="ctx">New / Delete</div>

// ✅ Good: referenced elements are interactive buttons
<button aria-actions="new-btn delete-btn">Options</button>
<button id="new-btn">New</button>
<button id="delete-btn">Delete</button>

focusgroup-valid-syntax

The focusgroup attribute must follow the syntax defined in the Focusgroup explainer:

focusgroup="<behavior> [inline|block] [wrap|nowrap] [nomemory]"

Valid behavior tokens: toolbar, tablist, radiogroup, listbox, menu, menubar, none.
none opts out of an ancestor focusgroup and must be used alone.

// ❌ Bad
<div focusgroup="">…</div>
<div focusgroup="toolbar inline block">…</div>
<div focusgroup="none nomemory">…</div>

// ✅ Good
<div focusgroup="toolbar">…</div>
<div focusgroup="tablist inline wrap">…</div>
<div focusgroup="none">…</div>

focusgroup-require-focusable-children

A focusgroup element must contain at least one focusable descendant (a natively focusable element such as <button>, <a href>, <input>, <select>, <textarea>, or any element with tabIndex >= 0). Nested focusgroup elements are treated independently and do not satisfy this requirement for their parent.

// ❌ Bad: no focusable children
<div focusgroup="toolbar"><span>Bold</span></div>

// ✅ Good
<div focusgroup="toolbar">
  <button>Bold</button>
  <button>Italic</button>
</div>

valid-role-for-element

Only the roles listed in the ARIA in HTML "ARIA role, state and property allowances" table may be used on an HTML element. The table is converted into src/utils/html-aria-roles.ts by pnpm generate.

The source files scripts/html-aria.html and scripts/roleInfo.js are git-ignored. Run pnpm generate:fetch to download them before generating (pnpm generate alone only works if they already exist locally).

// ❌ Bad
<header role="form">…</header>
<a href="/" role="heading">…</a>
<input type="color" role="button" />

// ✅ Good
<header role="group">…</header>
<a href="/" role="menuitem">…</a>
<span role="button">…</span>

Elements are checked only when the applicable row of the table can be determined from the element itself (e.g. a with href, img with alt, input with type and list, select with multiple/size). Dynamic attributes and attributes that may come from a spread are treated conservatively. Components, custom elements, dynamic role values, and elements whose allowed roles depend on ancestors (div, li, td, th, tr, figure, label, summary) are not checked.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages