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

Controls how scan results are presented.

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.

throttle

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

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.