Skip to main content
🎉 A11y Issue Detection Agent is now live! Detect accessibility issues like a WCAG expert with AI. Try now!
No Result Found
Connect & Get help from fellow developers on our Discord community. Ask the CommunityAsk the Community

Lint custom components

Lint custom UI components in your IDE and CI to catch issues early.

Custom component linting helps you get real-time accessibility feedback for your custom components. By declaring expected semantics and constraints for custom UI components, you can prevent regressions and guide developers toward accessible implementations.

Prerequisites

  • Accessibility DevTools installed in your environment (VS Code extension, JetBrains plugin, or CLI).
  • A repository containing your custom UI components.

Benefits

Linting custom components offers the following advantages:

  • Shift-left checks: Surface issues while coding in the IDE and during CI builds.
  • Team alignment: Share a single configuration so everyone follows the same rules.

Configure custom component linting

To enable custom linting, you need to create a configuration file and define how your components map to standard HTML elements.

Create the configuration file

  1. Create a configuration file in the root of your project using either JSON or YAML format, such as accessibility-devtools.config.json or accessibility-devtools.config.yaml.

  2. Add the following version declaration at the beginning of your file:

     version: 1
    

Define component mappings

Map your custom component names to standard HTML elements in the configuration file. The linter uses these mappings to analyze your custom components as if they were native HTML elements.

Component names are case-sensitive.

The following example shows a basic mapping:

{
  "components": {
    "react": {
      "PrimaryButton": {
        "element": "button"
      },
      "TextBox": {
        "element": "input"
      }
    }
  }
}

Configure attribute mapping

Map your custom props to specific HTML attributes to ensure the linter validates the correct values. You can configure the following mappings:

  • Attribute renaming: Map a custom prop (e.g., action) to a native attribute (such as type).
  • ARIA support: Use the wildcard aria-* to automatically map all props starting with aria- to the native element.
  • Text content: Map a specific prop (e.g., label) to the inner text content of the rendered element using the <text> tag.
  • Polymorphic components: If your component renders different tags based on a prop (e.g., as="h1"), map that prop to the <element> tag.

The following example demonstrates attribute mapping:

{
  "components": {
    "react": {
      "CustomButton": {
        "element": "button",
        "attributes": {
          "label": "<text>",
          "variant": "class",
          "aria-": "aria-",
          "as": "<element>"
        }
      }
    }
  }
}

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle