1. Documentation
  2. Forms
  3. Toggle
ReadmenpmGitHub
  • Introduction
  • Installation
  • Theming
  • Icons
  • Accordion
  • Card
  • Scroll Area
  • Separator
  • Sidebar
  • Field
  • Label
  • Input
  • Textarea
  • Number Field
  • OTP Field
  • Select
  • Combobox
  • Checkbox
  • Radio
  • Switch
  • Slider
  • Toggle
  • Calendar
  • Date Picker
  • File Upload
  • Button
  • Copy Button
  • Dropdown
  • Command
  • Tabs
  • Breadcrumb
  • Pagination
  • Tree
  • Table
  • Data Table
  • Stat
  • Timeline
  • Avatar
  • Status Bar
  • Badge
  • Meter
  • Empty
  • Skeleton
  • Spinner
  • Toast
  • Dialog
  • Sheet
  • Popover
  • Tooltip
  • Text
  • Kbd
  • Code Block
  • Utilities
  • Design rules

Toggle

A button that stays pressed — on its own, or welded into a group that remembers one choice.

Loading documentation…

Slider< PreviousCalendarNext >

Powered by heyo

On this page

UsageVariants and sizesSingle or multipleAttached and equalPropertiesToggleToggleGroup
<ToggleGroup defaultValue={["grid"]} attached><Toggle value="grid" variant="outline" icon={IconGrid} aria-label="Grid" /><Toggle value="list" variant="outline" icon={IconList} aria-label="List" /><Toggle value="columns" variant="outline" icon={IconColumns} aria-label="Columns" /></ToggleGroup>

A Toggle is a button that stays pressed: bold in an editor, a filter chip, a view mode. On its own it is a single on/off control; inside a ToggleGroup it becomes one of a set.

Usage

tsx
import { Toggle, ToggleGroup } from "@heyo-sh/heyo-ui";<ToggleGroup defaultValue={["grid"]} attached>  <Toggle value="grid" variant="outline" icon={IconGrid} aria-label="Grid" />  <Toggle value="list" variant="outline" icon={IconList} aria-label="List" /></ToggleGroup>;

Variants and sizes

ghost is the default — invisible until hovered, which is what an editor toolbar wants. outline draws its own edge and suits a standalone filter.

<Toggle icon={IconBold} aria-label="Bold" /><Toggle variant="outline" icon={IconItalic} aria-label="Italic" /><Toggle size="sm" variant="outline">Errors only</Toggle><Toggle size="xs" variant="outline">4xx</Toggle>

Single or multiple

A group is single-choice by default. Pass multiple and it behaves like a set of checkboxes — several filters at once.

<ToggleGroup defaultValue={["day"]}><Toggle value="day" variant="outline">Day</Toggle><Toggle value="week" variant="outline">Week</Toggle></ToggleGroup><ToggleGroup multiple defaultValue={["4xx", "5xx"]}><Toggle value="2xx" variant="outline" size="sm">2xx</Toggle><Toggle value="4xx" variant="outline" size="sm">4xx</Toggle><Toggle value="5xx" variant="outline" size="sm">5xx</Toggle></ToggleGroup>

Attached and equal

attached welds the buttons into one control, the way ButtonGroup does. equal gives every toggle the width of the widest one — on by default for a vertical group, where ragged right edges look like a mistake rather than a choice.

Toggle, Tabs or Radio?

A toggle group changes how something is displayed. Tabs change what is displayed. Radio collects a value you are going to submit.

Properties

Toggle

valuestringoptional

The value this toggle contributes inside a group.

pressed / defaultPressedbooleanoptional

Controlled and uncontrolled state, for a standalone toggle.

onPressedChange(pressed: boolean) => voidoptional

Fires when the toggle flips.

variant"ghost" | "outline"optional

It defaults to ghost.

size"xs" | "sm" | "base"optional

It defaults to base.

squarebooleanoptional

Forces a square, icon-only shape. Implied when there is no label.

iconIconLikeoptional

The glyph — a component, an element, or any node.

disabledbooleanoptional

Dims the control and ignores interaction.

ToggleGroup

value / defaultValuestring[]optional

Controlled and uncontrolled selection. Always an array, even when single.

onValueChange(value: string[]) => voidoptional

Fires when the selection changes.

multiplebooleanoptional

Allows several toggles to be pressed at once.

attachedbooleanoptional

Welds the buttons into a single control.

equalbooleanoptional

Gives every toggle the width of the widest. It defaults to true for vertical, false for horizontal.

orientation"horizontal" | "vertical"optional

The layout axis. It defaults to horizontal.

disabledbooleanoptional

Dims every toggle in the group.