API

Exports

Type exports

The following types are exported for TypeScript consumers:

Options

axeOptions

Type: object.

Default: {}.

The options parameter for axe.run().

Accented supports only two keys of the original options object:

Both are optional and control which accessibility rules Accented tests against.

See axe-core options documentation.

callback

Type: function.

Default: no-op (() => {}).

A function that will be called after each scan.

Potential uses include sending results to a backend or measuring performance.

It accepts a single params object with the following properties:

Example:

accented({
  callback: ({ elementsWithIssues, performance, scanContext }) => {
    console.log('Elements with issues:', elementsWithIssues);
    console.log('Total blocking time:', performance.totalBlockingTime);
    console.log('Scan context:', scanContext);
  },
});

context

Type: see details below.

Default: document.

The context parameter for axe.run().

Determines what part(s) of the page to scan for accessibility issues.

Accepts a variety of shapes:

See also the documentation for the context parameter of axe.run(), which the context option from Accented mostly mirrors (note that Accented doesn’t support the fromFrames object shape).

name

Type: string.

Default: 'accented'.

The character sequence that’s used in various elements, attributes and stylesheets that Accented adds to the page.

You likely don’t need to set this unless your page already uses “accented” in element names or attributes, which could cause conflicts.

Only lowercase alphanumeric characters and dashes (-) are allowed in the name, and it must start with a lowercase letter.

Example:

accented({
  name: 'my-name',
});

With the above option provided, the attribute set on elements with issues will be data-my-name, a custom element will be called my-name-trigger, and so on.

output

By default, scan results are presented in two ways:

You can use the output option if you’d like to only keep one or the other.

For example, you may only keep the console messages if you don’t want Accented to modify the DOM of your app (see Console-only mode).

Or, may be fine with the highlights on the page, but prefer not to clutter the console.

output.console

Type: boolean.

Default: true.

Whether the list of elements with issues should be printed to the browser console whenever issues are added, removed, or changed.

Example:

accented({
  output: {
    console: false
  }
});

In the example, the issues will not be logged to the console, while elements on the page will still be highlighted.

output.page

Added in: v1.1.0.

Type: boolean.

Default: true.

Whether Accented should highlight elements with issues on the page.

Example:

accented({
  output: {
    page: false
  }
});

In the example, the issues will only be logged to the console, with no highlights on the page.

throttle

An object controlling at what moments Accented will run its scans.

Learn more about throttling in Accented.

throttle.wait

Type: number.

Default: 1000.

How long (in ms) Accented waits to run a scan after a mutation or after the previous scan finishes — whichever is later.

If the page you’re scanning has a lot of nodes, scanning may take a noticeable time (~ a few hundred milliseconds), during which time the main thread will be blocked most of the time.

You may want to experiment with this value if your page contents change frequently or if it has JavaScript-based animations running on the main thread.

throttle.leading

Type: boolean.

Default: true.

If leading is set to true, the scan runs immediately after a mutation. In this case, wait only applies to subsequent scans, giving the page at least wait milliseconds between the end of the previous scan and the beginning of the next one.

If false, Accented waits before the first scan too — useful if you expect batches of rapid mutations.

Styling

You can control what some aspects of Accented UI look like by setting the following props in your application (see Styling in Getting started for a discussion of when you might need this):

Note: Accented’s default values are defined within @layer accented, so if you use the default layer to define your custom properties, they’re guaranteed to take precedence over the default ones. Learn more about CSS layers.

Note: when you set the name option, the custom property names and CSS layer will follow that value.

For example, if name: 'my-name', then the CSS custom properties will be --my-name-primary-color, --my-name-secondary-color, and so on, and those will be defined within @layer my-name.