Components

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.

<template>
  <Button disabled>Unavailable</Button>
</template>

Async loading

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

<script setup lang="ts">
async function save() {
  await api.save();
}
</script>

<template>
  <Button loading-auto @click="save">Save</Button>
</template>

Custom loading content

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

<template>
  <Button :loading="isSaving">
    Save
    <template #loading>
      <span>Saving…</span>
    </template>
  </Button>
</template>

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

<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.

<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.
uiButtonUiClasses for root and default loading parts.

Slots

SlotScoped propsDescription
defaultButton label / content.
loadingContent 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.