Skip to content

Button

A button that can show a loading state during async operations.

Button adds disabled and loading state to a native <button>. The as prop can render another element or component.

Anatomy

  • #default: Button label or content.
  • #loading: Content shown while loading. Defaults to the built-in spinner.

Usage

Examples

Disabled state

Use disabled for actions that cannot currently run.

vue
@layer akaza-reset;
@import "tailwindcss";
@import "akaza-ui/dist/akaza-ui.css";

Async loading

Set loading-auto to show a spinner while the @click handler's Promise is pending.

vue
<template>
  <Avatar
    src="/avatar.jpg"
    alt="Jane Doe"
    text="JD"
    :delay-ms="300"
  />
</template>

Custom loading content

Use #loading when the default spinner does not match your UI.

vue
<Button
  :ui="{
    root: 'rounded-md bg-black px-3 py-2 text-white',
    spinner: 'size-4 animate-spin',
  }"
>
  Save
</Button>

Use as to render a different root while keeping Akaza button state hooks.

vue
<template>
  <Button
    as="a"
    href="/docs"
  >
    Read the docs
  </Button>
</template>

Focusable when disabled

Keeps the button in the tab order while disabled. This allows a disabled button to trigger a tooltip.

vue
<template>
  <Button
    disabled
    focusable-when-disabled
  >
    Restricted
  </Button>
</template>

API Reference

Props

PropTypeDefaultDescription
asstring | Component"button"Element or component to render as.
type"button" | "submit" | "reset""button"HTML button type. Only applied when as="button".
disabledbooleanfalseDisables the button.
focusableWhenDisabledbooleanfalseKeep button focusable while disabled.
loadingbooleanfalseShow the loading state manually.
loadingAutobooleanfalseShows loading while the @click handler's Promise resolves.
uiButtonUi—Classes for root and default loading parts.

Slots

SlotScoped propsDescription
default—Button label / content.
loading—Content shown during the loading state. Defaults to a spinner icon.

Native Events

Button forwards native button events to the root element. Bind @click as usual. With loading-auto, a Promise returned by the handler keeps the button in its loading state until the Promise settles.

UI Options

KeyDescription
rootThe button element or custom rendered root.
spinnerThe default loading spinner.
loadingTextThe visually hidden default loading text.

Styling Hooks

UI keyCSS classData attrs
rootakaza-buttondata-akaza-state, data-akaza-disabled, data-akaza-loading
spinnerakaza-button-spinner—
loadingTextakaza-button-loading-text—

Plain class also applies to the root button. Use ui.root when styling root together with spinner or loadingText.

Keyboard

KeyBehavior
Enter / SpaceActivates native button and custom as roots.
TabFocuses enabled button, or a disabled button only with focusableWhenDisabled.

Non-button roots receive role="button", keyboard activation, and tab behavior. Loading and disabled states block activation.

Edit this page on GitHub ↗