A11y Async Button

Addon example

Async button presets

Reuse consistent loading, success, error, reset, and width-preserving defaults for common actions without repeating the same options across every button.

Quick facts

What this addon covers

Import path
a11y-async-button/addons/presets
Pattern
Named option presets for common async actions
Built-ins
save, submit, send, delete, upload, download, copy, refresh
Runtime deps
None beyond the core package

Live demo

Use named presets for repeated actions

Each button uses data-a11y-async-preset. The JavaScript supplies only the actual async work and one project-specific archive preset.

Save settings

Ready to save settings.

Send invite

Ready to send an invite.

Delete draft

Ready to delete the draft.

Archive report

Ready to archive the report.

Try it

Useful checks

Example code

Import only the presets addon

import { initAsyncButtonPresets } from "a11y-async-button/addons/presets";
import "a11y-async-button/styles.css";

initAsyncButtonPresets({
  presets: {
    archive: {
      loadingText: "Archiving...",
      successText: "Archived",
      errorText: "Could not archive",
      resetDelay: 2200,
      preserveWidth: true
    }
  },
  onAction: async (asyncButton) => {
    await runActionFor(asyncButton.element);
  }
});

Accessibility notes

What changes for users

Keyboard and focus

  • Each action stays a real <button> with native keyboard activation.
  • Focus remains on the activated button while the preset text changes.
  • Repeated activation is blocked by the core async button defaults while work is loading.

Status output

  • The preset chooses clear loading, success, and error copy for the action type.
  • This demo listens to core state-change events to update visible status text.
  • The addon does not run network requests, confirm destructive actions, or create UI.