Skip to contentKino
Skip to Content

Toggle

A button that stays pressed until it is pressed again. Pressed, it fills, and it never changes size.

npx shadcn add https://kinoui.com/r/toggle.json
Share on

Examples

LED-482 · Invoice totals are off by a cent

Ledger web app · opened by Priya Raman 2 days ago
Priya Raman

Starred · in your sidebar

Default

A button that stays pressed until it is pressed again. Off it is quiet; pressed it fills, at the same size, and a ToggleIcon rolls to its pressed icon. An icon-only toggle needs an aria-label that names what it does, which stays the same pressed or not.

Sizes

The Button's sizes: sm, default and lg for a label, and icon-sm, icon and icon-lg for an icon alone, which are square.

Installation

npx shadcn@latest add https://kinoui.com/r/toggle.json
Files
lib/refs.tslib/reduce-motion.tslib/resize.tslib/swap.tsxcomponents/kino/spinner.tsxcomponents/kino/button.tsxcomponents/kino/toggle.tsx
Packages
@base-ui/reactclass-variance-authority

New to Kino? Installation covers what your project needs first and the @kino namespace.

API reference

Toggle

PropTypeDefaultDescription
pressedbooleanNoneWhether it is pressed, when you own the state. defaultPressed when you don’t.
onPressedChange(pressed: boolean) => voidNoneCalled with the new state.
variant'default''outline''default'How it looks off: no border, or a border. Pressed, both fill.
size'sm''default''lg''icon-sm''icon''icon-lg''default'Its height, from the density tokens. An icon size is square.

ToggleIcon

PropTypeDefaultDescription
childrenReactNodeNoneThe icon at rest.
pressedIconReactNodeNoneThe icon while pressed, such as a filled star for an outline one.

Data attributes

AttributeOnDescription
data-pressedTogglePresent while it is pressed.
data-disabledTogglePresent while it is disabled.

CSS variables

VariableSet it onDefaultDescription
--swap-rollToggle, or <body>55% of its heightHow far a ToggleIcon rolls: the old icon leaves up, the new one rises.
--swap-scaleToggle, or <body>0.8How far the icon shrinks as it fades.
--swap-blurToggle, or <body>2pxHow far the icon blurs as it fades.

Accessibility

  • It is a <button> with aria-pressed, so a screen reader says “toggle button, pressed”. Space and Enter press it.
  • Name an icon-only toggle with aria-label, and keep the name the same pressed or not: the pressed state is announced on its own.
  • Pressed is shown by a fill and by the label’s colour; in forced colours the fill takes the system’s highlight. A ToggleIcon adds a second sign, its pressed icon.