Veil UI
Components

Loading Button

A button that shows a spinner and disables itself while busy.

Installation

$ npx veil-ui@latest add loading-button

Usage

import { LoadingButton } from "@/components/ui/loading-button";

<LoadingButton loading={isSaving} loadingLabel="Saving">
  Save changes
</LoadingButton>;

Examples

Basic

Loading

Toggle

The label stays in place while the spinner appears, so the button does not change width and the action remains recognizable.

API reference

PropTypeDefaultDescription
loadingbooleanfalseShow a spinner, set aria-busy and disable the button.
loadingLabelstring"Loading"Screen-reader text for the loading state.
...propsButtonProps—All Button props and native button attributes.

Accessibility

  • Sets aria-busy and disables the button while loading to prevent double submission.
  • The spinner is a polite status region with screen-reader-only text.
  • Keep the visible label mounted so the accessible name stays stable.

Vue and plain HTML

This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add loading-button --framework vue or switch the framework in components.json.

<script setup lang="ts">
import { Button } from "@/components/ui/button";
import { Spinner } from "@/components/ui/spinner";

defineOptions({ inheritAttrs: false });

const props = withDefaults(
  defineProps<{
    /** Show a spinner and disable the button. */
    loading?: boolean;
    /** Screen-reader text while loading. */
    loadingLabel?: string;
    disabled?: boolean;
    class?: string;
  }>(),
  { loading: false, loadingLabel: "Loading" },
);
</script>

<template>
  <Button
    data-slot="loading-button"
    :aria-busy="loading"
    :disabled="disabled || loading"
    v-bind="$attrs"
    :class="props.class"
  >
    <Spinner v-if="loading" size="sm" :label="loadingLabel" />
    <slot />
  </Button>
</template>

On this page