A11y Async Button

Addon example

Async retry helper

Recoverable actions can expose a clear try-again path while preserving semantic button behavior, loading state, success text, and final failure messaging.

Quick facts

What this addon covers

Import path
a11y-async-button/addons/retry
Pattern
Recoverable async action helper
Attempts
Caller-owned async work with addon-owned retry state
Runtime deps
None beyond the core package

Live demo

Retry recoverable failures

The save action fails once, then succeeds on retry. The upload action always fails so the final error path is visible.

Save after one failed attempt

Ready to save.

Stop after max attempts

Ready to upload.

Try it

Useful checks

Example code

Import only the retry addon

import { createAsyncButtonRetry } from "a11y-async-button/addons/retry";
import "a11y-async-button/styles.css";

createAsyncButtonRetry(button, {
  maxAttempts: 3,
  retryText: "Try saving again",
  finalErrorText: "Save failed",
  onAttempt: async () => {
    await saveChanges();
  }
});

Accessibility notes

What changes for users

Keyboard and focus

  • The addon keeps native button activation for Enter and Space.
  • Focus stays on the button while text and state change.
  • Final failure prevents more attempts until the caller resets the instance.

Status output

  • The button uses the core loading, success, error, and live-region behavior.
  • The visible status text listens to retry lifecycle events in this demo.
  • No network request, storage, analytics, or retry backoff is built into the addon.