Button
Button.Root is the control. Button.Icon is a compound part. Icon position is DOM order. The icon is decorative (aria-hidden). Icon-only roots need aria-label or aria-labelledby on Button.Root.
On this page
Icon-only roots tip that name. A labeled button tips the full string only while the label overflows. tooltip={false} opts out. Fitting labeled buttons do not tip. Auto tips are never interactive.
Variants use the existing paint packs. critical is the irreversible action in a confirm dialog, such as Delete next to a secondary Cancel. Default type is button. aria-disabled="true" draws the button as disabled but keeps it focusable, for a button that turns unavailable while it may have focus, such as Next at the last page: disabled would drop that focus to the page. A click then does nothing: onClick doesn't run, a toggle doesn't flip, and the button submits no form and follows no link.
Hover fades the colors over control.motion.duration, and a press changes them at once. A brand can also shrink a pressed button with button.base.motion.press.scale, such as 0.97. It is 1 by default, so a button holds still. Set it in your theme or a ThemeProvider override, which reaches the buttons inside it, not on a button itself. The button shrinks at once by a transform and grows back over control.motion.duration when let go. Nothing around it moves, and the pointer still hits the whole button where it rests, so a press near its edge keeps its hover and still clicks. A tip on the button moves with it and keeps its gap. A browser without container style queries leaves every button still. A disabled button and the segments of a Button.Group or a horizontal ToggleGroup keep their size, and under reduced motion no button scales.
import { Button } from '@tounsoo/todae';
export default function ButtonVariants() {
return (
<>
<Button.Root>Save</Button.Root>
<Button.Root variant="secondary">Cancel</Button.Root>
<Button.Root variant="ghost">Ghost</Button.Root>
<Button.Root variant="critical">Delete</Button.Root>
<Button.Root disabled>Disabled</Button.Root>
</>
);
}
Leading icon, trailing icon, icon-only.
import { Button } from '@tounsoo/todae';
import { ArrowRight, Plus } from 'lucide-react';
export default function ButtonIcons() {
return (
<>
<Button.Root>
<Button.Icon>
<Plus />
</Button.Icon>
Save
</Button.Root>
<Button.Root variant="secondary">
Next
<Button.Icon>
<ArrowRight />
</Button.Icon>
</Button.Root>
<Button.Root aria-label="Add">
<Button.Icon>
<Plus />
</Button.Icon>
</Button.Root>
</>
);
}
Overflowing label.
import { Button } from '@tounsoo/todae';
export default function ButtonOverflow() {
return (
<div style={{ width: 96 }}>
<Button.Root>Very long archive label</Button.Root>
</div>
);
}
Toggle
Pass pressed or defaultPressed and the button becomes a toggle: it sets aria-pressed and flips on click, unless it is aria-disabled. onPressedChange gets the new state. A pressed button keeps the active colors with an inset ring. For a set of toggles, use ToggleGroup.
import { Button } from '@tounsoo/todae';
import { useState } from 'react';
export default function ButtonToggle() {
const [muted, setMuted] = useState(false);
return (
<Button.Root variant="secondary" pressed={muted} onPressedChange={setMuted}>
Mute
</Button.Root>
);
}
Button.Group
Sibling chrome. role="group". Children are Button.Root. Attached edges overlap by the border width and share the outer radius. No selection state.
import { Button } from '@tounsoo/todae';
import { AlignCenter, AlignLeft, AlignRight } from 'lucide-react';
export default function ButtonGroupAlign() {
return (
<Button.Group aria-label="Align">
<Button.Root variant="secondary" aria-label="Left">
<Button.Icon>
<AlignLeft />
</Button.Icon>
</Button.Root>
<Button.Root variant="secondary" aria-label="Center">
<Button.Icon>
<AlignCenter />
</Button.Icon>
</Button.Root>
<Button.Root variant="secondary" aria-label="Right">
<Button.Icon>
<AlignRight />
</Button.Icon>
</Button.Root>
</Button.Group>
);
}
Icons
Button.Icon takes an icon from any library, such as Lucide, Phosphor or Tabler. An svg or img directly inside it takes the button.base.icon.size token, whatever the icon's own size or width. An icon-only button is a square as tall as a labeled one.
import { Button, Stack } from '@tounsoo/todae';
import { ArrowRight as PhArrowRight, GearSix, Plus as PhPlus } from '@phosphor-icons/react';
import { IconArrowRight, IconPlus, IconSettings } from '@tabler/icons-react';
import { ArrowRight, Plus, Settings } from 'lucide-react';
export default function ButtonIconLibraries() {
return (
<Stack.Root>
<Stack.Root direction="row">
<Button.Root>
<Button.Icon>
<Plus />
</Button.Icon>
Lucide
</Button.Root>
<Button.Root variant="secondary">
Next
<Button.Icon>
<ArrowRight />
</Button.Icon>
</Button.Root>
<Button.Root variant="secondary" aria-label="Lucide settings">
<Button.Icon>
<Settings />
</Button.Icon>
</Button.Root>
</Stack.Root>
<Stack.Root direction="row">
<Button.Root>
<Button.Icon>
<PhPlus />
</Button.Icon>
Phosphor
</Button.Root>
<Button.Root variant="secondary">
Next
<Button.Icon>
<PhArrowRight />
</Button.Icon>
</Button.Root>
<Button.Root variant="secondary" aria-label="Phosphor settings">
<Button.Icon>
<GearSix />
</Button.Icon>
</Button.Root>
</Stack.Root>
<Stack.Root direction="row">
<Button.Root>
<Button.Icon>
<IconPlus />
</Button.Icon>
Tabler
</Button.Root>
<Button.Root variant="secondary">
Next
<Button.Icon>
<IconArrowRight />
</Button.Icon>
</Button.Root>
<Button.Root variant="secondary" aria-label="Tabler settings">
<Button.Icon>
<IconSettings />
</Button.Icon>
</Button.Root>
</Stack.Root>
</Stack.Root>
);
}
Links
A link that should look like a button is still a link: it goes somewhere, Enter follows it, and screen readers list it with the page's links. Pass render and return the link with the props it is handed, the way a router plugs into Link. The button keeps its look, its icons and its tips, and the element keeps its own role. type, disabled and pressed are not allowed with render, since a link takes none of them. An a without href goes nowhere and looks disabled. render must return an a or a button; anything else logs an error in development. A button it returns sets its own type.
import NextLink from 'next/link';
<Button.Root render={(props) => <NextLink {...props} href="/guides/build-on-todae" />}>
Get started
</Button.Root>
<Button.Root variant="secondary" render={(props) => <a {...props} href="https://github.com/tounsoo/todae" />}>
Source
</Button.Root>
Button.Root is a client component, so a Server Component can't pass it a render function. Write the link in a client component of your own and render that. Type its props as Omit<ButtonRenderedProps, 'render'> plus the href it takes, so every other Button.Root prop still reaches the link.
import { Button } from '@tounsoo/todae';
import { ArrowRight } from 'lucide-react';
/** Links drawn as buttons through render. The one without href looks disabled. */
export default function ButtonLinks() {
return (
<>
<Button.Root render={(props) => <a {...props} href="https://www.npmjs.com/package/@tounsoo/todae" />}>
Install
<Button.Icon>
<ArrowRight />
</Button.Icon>
</Button.Root>
<Button.Root variant="secondary" render={(props) => <a {...props} href="https://github.com/tounsoo/todae" />}>
Source
</Button.Root>
<Button.Root variant="secondary" render={(props) => <a {...props} />}>
Not yet available
</Button.Root>
</>
);
}
Accessible composition
Todae handles: A native <button> with type="button", so it keeps the browser's keyboard behaviour, and a focus ring on :focus-visible. With render, the element keeps its own role; Todae adds none. pressed sets aria-pressed. Button.Icon is aria-hidden. An icon-only root shows its aria-label or aria-labelledby text as a tooltip, and logs an error in development when it has no name. The tip repeats the name, so it is hidden from screen readers and adds nothing to aria-describedby, and the name is read once. Button.Group is always role="group".
You supply: A name for every icon-only button, and an aria-label for each Button.Group. A wrapper whose buttons can be icon-only should require the name in its props type, pass it as aria-label, and spread the rest so ref and disabled reach the button.
import type { ReactNode } from 'react';
import { Button, type ButtonRootProps } from '@tounsoo/todae';
type IconButtonProps = Omit<ButtonRootProps, 'aria-label' | 'aria-labelledby' | 'children'> & {
label: string;
icon: ReactNode;
};
export function IconButton({ label, icon, ...props }: IconButtonProps) {
return (
<Button.Root {...props} aria-label={label}>
<Button.Icon>{icon}</Button.Icon>
</Button.Root>
);
}
Watch for: A wrapper that drops the rest props, which loses ref and ARIA. A Button.Root inside a link, or a link inside a button: interactive content cannot nest, so draw the link as the button with render instead. A toggle whose text flips, such as "Mute" to "Unmute", as aria-pressed changes; keep one label and let pressed carry the state. tooltip={false} on an icon-only button, which removes its only visible name. On an icon-only button, or one whose label is cut off, an onPointerEnter or onFocus that calls preventDefault(), which stops the automatic tooltip from showing; your aria-describedby stays as you set it.
When to use
Button.Root
When: One action in a native button. Variants primary / secondary / ghost / critical; default type="button". critical confirms an irreversible action, such as deleting an account, and sits beside a secondary cancel. Icon-only needs aria-label, which it auto-tips.
When not: Navigation in text → Link; navigation that looks like a button → Button.Root with render. A setting that takes effect at once → Switch. A form choice → Checkbox. Selected segment → ToggleGroup (Button.Group has no selection). critical for an action the person can undo, or for status text that is not an action → Alert tone="critical".
Button.Icon
When: Decorative icon inside Button.Root. Position = DOM order. Always aria-hidden.
When not: Icon in a field → Field.Icon. Icon as the only name with no aria-label on Root. Outside Button.Root.
Button.Group
When: Attached horizontal row of related Button.Root actions (role="group"). Name it with aria-label.
When not: Toggles → ToggleGroup (no selection state here). Vertical or wrapping rows → Stack. Unrelated actions → separate buttons in Stack.
Props
| Name | Type | Description |
|---|---|---|
variant | "primary"| "secondary"| "ghost"| "critical" | Visual style. Non-primary sets data-button-variant. Default: "primary" |
type | "button" | "submit" | "reset" | Native button type. Default: "button" |
disabled | boolean | Disables the control. Default: false |
aria-label | string | Required accessible name when the only child is Button.Icon. Auto-tip text for icon-only. |
tooltip | boolean | Icon-only tips the accessible name. Overflowing labels tip the full string. False opts out. Never tips a fitting labeled button. Default: true |
pressed | boolean | Controlled pressed state. Makes the button a toggle with aria-pressed. |
defaultPressed | boolean | Starting pressed state for an uncontrolled toggle. Makes the button a toggle with aria-pressed. |
onPressedChange | (pressed: boolean) => void | Called with the new state when a toggle is clicked. onClick runs first; preventDefault() there skips the change. |
children | React.ReactNode | Label and optional Button.Icon. Order is leading or trailing. |
render | (props: ButtonRenderProps) => React.ReactElement | Draws the button on another element, such as an a or a router link. It receives every prop, ref included, and must pass them to an a or a button. The element keeps its own role, so type, disabled and pressed are not allowed; an a without href looks disabled. |
| Name | Type | Description |
|---|---|---|
children | React.ReactNode | Icon graphic. |
| Name | Type | Description |
|---|---|---|
aria-label | string | Accessible name for the group. |
children | React.ReactNode | Button.Root children. Horizontal only. |