Skip to Content
zjkm-ui
Components

Loading Button

A button that spins while busy, then shows a tick.

Props
<LoadingButton>
  Save
</LoadingButton>

Installation

npx shadcn@latest add https://ui.zjkm.tech/r/loading-button.json
import { LoadingButton } from "@/components/loading-button"

Using JavaScript? Set tsx: false in components.json and the CLI converts it.

New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.

Usage

Pass the task's state. While loading, the button shows a spinner, is disabled and sets aria-busy. On success it draws a tick. The label stays in place, hidden, so the width never jumps. Click the demo to run a fake task.

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

export function SaveButton({ save }: { save: () => Promise<void> }) {
  const [state, setState] = useState<"idle" | "loading" | "success">("idle");
  return (
    <LoadingButton
      state={state}
      onClick={async () => {
        setState("loading");
        await save();
        setState("success");
      }}
    >
      Save
    </LoadingButton>
  );
}

Props

PropTypeDefaultDescription
childrenReactNodeThe label.
state"idle" | "loading" | "success""idle"What the task is doing.
...propsbutton propsEvery native <button> prop: onClick, disabled, type and so on.

With reduced motion, the spinner turns slowly and the tick appears without drawing.

On this page