Docs / Primitives / Toggle
Toggle
A two-state button, and a group of them with single or multiple selection. Dark mode is
controlled by the parent through isDark; the toggle below lives outside the
component.
Variants and sizes
Controlled
Bold is off
Disabled
Single selection
Alignment: left
Multiple selection, joined
Formatting: bold
Vertical
Grid starts pressed, but Tab enters the group on its first item, like Base UI.
Consumer handlers
Your own onclick or onkeydown runs first and the built-in behavior
still runs.
Consumer clicks: 0
Last key: none
Large pressed: not reported
Items added later
Inside a form
type and form are ignored, like Base UI, so a toggle never submits
a form.
Form submits: 0
Disabled group
Differences from upstream
- Built on plain buttons instead of the Base UI
ToggleandToggleGroupprimitives (React-only), soTogglePrimitiveandToggleGroupPrimitiveare not exported. Props follow Base UI:pressed,defaultPressed,onPressedChange,value,defaultValue,onValueChange,multiple(defaultfalse),loopFocus,disabled,orientation, plus upstream'sspacing. - A consumer
onclickoronkeydownruns before the built-in handler, like Base UI. To skip the built-in behavior, callevent.preventDefault(); Base UI'sevent.preventBaseUIHandler()does not exist on DOM events. - The Tab stop starts on the first item in DOM order and then follows focus, like Base UI 1.4.1. Two deliberate changes: when the first item is disabled the stop moves to the next enabled item (Base UI leaves the group with no Tab stop), and the remembered stop follows the focused item rather than its position when items are added or removed.
- Like Base UI,
typeandformare ignored: a toggle always renderstype="button"and never joins a form. classNameandclassare both accepted;childrenis a Svelte snippet.- The before-pseudo shadow, touch hit-area, and icon sizing utilities from upstream's class list are not ported; variants and sizes are.
- Accepts
isDarkandonIsDarkChange; it reflectsisDarkand never callsonIsDarkChange. ToggleGrouprendersdata-orientationbut not Base UI'saria-orientation, which ARIA does not allow onrole="group".