Button

Starts an action, for people and agents.

Source
$npx @dinachi/cli@latest add button
variant
size
children
disabled

Usage

import { Button } from "@/components/ui/button"

export function SaveButton() {
  return <Button onClick={() => save()}>Save changes</Button>
}

Examples

Each visual style, from default to destructive.
import { Button } from '@/components/ui/button';

export function Example() {
  return (
    <div className="flex gap-2 flex-wrap">
      <Button variant="default">Default</Button>
      <Button variant="secondary">Secondary</Button>
      <Button variant="outline">Outline</Button>
      <Button variant="ghost">Ghost</Button>
      <Button variant="link">Link</Button>
      <Button variant="destructive">Destructive</Button>
    </div>
  );
}

Notes

Submitting a form

Unlike a native <button>, Button does not submit by default. Pass type="submit".

Rendering another element

  • With render, nativeButton defaults to false and the element gets role="button" and keyboard handling.
  • Pass nativeButton when render is itself a <button>, such as another component's trigger.
  • For a link, style an <a> with buttonVariants(). Rendered through Button, it is announced as a button.

Loading states

Pair disabled with focusableWhenDisabled to keep focus on the button. If its text changes, point aria-labelledby at the text so the change is announced.

Agents

  • Not registered with the agent bridge. Inside an AgentProvider it is read from the page as a button, named by its text or aria-label, and takes press.
  • A disabled button refuses.
  • Set data-agent-confirm to a reason to require approval for each press.

API

variant"default" | "destructive" | "outline" | "secondary" | "ghost" | "link" = "default"
The visual style.
size"default" | "sm" | "lg" | "icon" = "default"
Height and padding. icon is square, for a single icon.
renderReactElement | (props, state) => ReactElement
Swap the element, keep the behaviour.
nativeButtonboolean = true, or false with render
Whether the rendered element is a real <button>. Set true when render is a button.
disabled
agent
boolean = false
Blocks clicks and agent presses.
focusableWhenDisabledboolean = false
Keeps a disabled button in the tab order, for loading states.
type"button" | "submit" | "reset" = "button"
Pass "submit" to submit the form.
classNamestring
Merged over the variant classes.

Accessibility

  • A native button, or role="button" when nativeButton is false.
  • Name an icon-only button with aria-label; a tooltip does not name it. The agent reads the same name.
  • A disabled button leaves the tab order unless focusableWhenDisabled is set.
  • Reduced motion turns off the press animation.