Toggle Group

new

Like a button group, but they remember what you picked

Demo

Open Props in the corner of the example to try activeVariant, color, orientation and disabled.

Installation

Usage

<script setup lang="ts">
import { Bold, Italic, Underline } from '@lucide/vue'

import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group'

const formatting = ref<string[]>([])
</script>

<template>
  <ToggleGroup v-model="formatting" type="multiple" variant="outline" size="icon-md">
    <ToggleGroupItem value="bold" aria-label="Bold"><Bold /></ToggleGroupItem>
    <ToggleGroupItem value="italic" aria-label="Italic"><Italic /></ToggleGroupItem>
    <ToggleGroupItem value="underline" aria-label="Underline"><Underline /></ToggleGroupItem>
  </ToggleGroup>
</template>

ToggleGroup is Reka UI's toggle group laid out like a Button Group: the items join, with the inner corners squared and outlined edges shared. Tab reaches the group once, and the arrow keys move between its items. Each item is a Toggle and takes its variants, colours and sizes.

Examples

Single

type="single" keeps at most one item on and binds its value as a string; type="multiple" binds an array.

Single

Style

variant, activeVariant, color, activeColor and size on the group apply to every item, and an item's own props override them.

Outline

API Reference

class is also accepted on every part and merged over its classes with tailwind-merge.

Data attributes

data-slotAttributesDescription
toggle-groupdata-orientation, data-sizeThe group, with role="group".
toggle-group-itemdata-state, data-variant, data-color, data-active-color, data-size, data-disabledOne toggle. data-state is on or off.

Changelog

  1. registry 0.22.0

    ac9afad — An aria-disabled Toggle, ToggleGroupItem or ToolbarToggleItem ignores click, Enter and Space like an aria-disabled Button, so a toolbar toggle kept focusable for its tooltip no longer changes the model. swallowWhenDisabled moves to @/ui/button, where the three parts share it.

    ea2717b — In a ToggleGroup (or a ButtonGroup of toggles) whose activeVariant is outline or subtle, pressed neighbours share one edge instead of drawing two side by side: Toggle and ToggleGroupItem carry data-active-variant, and the group overlaps them by that edge as it does for an outline variant.

  2. core 0.16.0

    8329332 — SwipeActions: an arrow key that a widget inside the row already handled (a ToggleGroup or other roving-focus group calls preventDefault) no longer opens or closes the row.

  3. registry 0.21.0

    e5495ef — size works the same way everywhere. Every component exports its size type (AlertSize, BadgeSize, CardSize, CheckboxSize, RadioSize, SwitchSize, EmptySize, InputFloatingSize, ItemSize, ListboxSize, SeparatorSize, SliderSize, StepperSize, TabsSize, TextareaSize, TimelineSize) and the props take it without null; Button-based parts take ButtonSize, Input TextControlSize, SelectTrigger SelectSize and Tree TreeSize. ToggleGroup and ToolbarToggleGroup carry data-size on the group as well. Table's row heights moved into tableSize, so a class on DataTable's ui.table overrides --table-row-h at every size, not only at md.

    5ada64b — A pressed Toggle or ToggleGroup item keeps its on look inside TooltipTrigger as-child (or any wrapper that writes its own data-state). The on styles read aria-pressed, which Reka sets on every toggle, instead of data-state="on", which the tooltip overwrote with closed; core's active-colour rules match both, so a custom [data-state="on"][data-active-color] rule keeps working.

  4. core 0.15.1

    5ada64b — A pressed Toggle or ToggleGroup item keeps its on look inside TooltipTrigger as-child (or any wrapper that writes its own data-state). The on styles read aria-pressed, which Reka sets on every toggle, instead of data-state="on", which the tooltip overwrote with closed; core's active-colour rules match both, so a custom [data-state="on"][data-active-color] rule keeps working.

  5. registry 0.15.0

    d09f26a — Pressable parts ripple on their own: Button, Toggle, ToggleGroupItem, Item as a link or a button, the calendar days, tabs, accordion, menubar and navigation menu triggers, the items of Menu, Menubar, Select, Combobox, Command, DrawerMenu, Listbox and Tree, and the clear buttons of TagsInput and Combobox. Each imports the directive from @/lib/ripple, so add brings the ripple item along and nothing needs registering. On menu, listbox and tree rows the wave replaces the pressed layer, as state-layer already did. Bind v-ripple="false" on a Button to turn one off, or set --kappa-ripple: none on :root to turn them all off.

  6. registry 0.13.0

    93e57a0 — Every size on the control scale is named xs to xl; default and the bare icon are gone. To move over:

    - Button: size="default" becomes size="md", or leave size out; size="icon" becomes size="icon-md". The full set is xs to xl and icon-xs to icon-xl. Toggle, ToggleGroup, ToggleGroupItem, the Toolbar parts, AlertDialogAction, AlertDialogCancel and ToastAction take the same names; Button, Toggle and ToggleGroup default to md, the Toolbar parts keep sm and ToastAction keeps xs. InputGroupButton keeps its own xs, sm, icon-xs and icon-sm, 24 and 32px to fit inside the group, xs by default. Pagination hands its md to Button as it is. Button, Toggle and ToggleGroupItem set data-variant, data-color and data-size even when you leave them at their defaults. - AlertDialogContent: size="default" becomes size="md", still the default; sm is unchanged. The size option of useConfirm's confirm, alert and prompt takes the same names. - Table and DataTable: density becomes size, data-density becomes data-size, and the TableDensity type is now TableSize. sm, md and lg keep their 36, 44 and 52px rows; xs (28px) and xl (60px) are new, and DataTable's virtual row estimates cover them. The cells' padding above and below the text is now --table-cell-py on the table: 8px as before, 3px at xs. At xs, DataTable's sort buttons and expand and group toggles shrink to fit the row. The table-density example is now table-sizes. - DrawerMenu: size takes xs to xl like Menu and reads the control scale, plus room for a thumb. sm, md and lg keep their 40, 48 and 56px rows, padding and icons; xs is 36px and xl 64px. Overriding a --control-* token on :root now resizes DrawerMenu rows as well. - Select and Combobox: the list opens at the trigger's or anchor's size instead of always at md, so <SelectTrigger size="xl"> opens an xl list. size on SelectContent or ComboboxList picks another. Behind an as-child button, set size on ComboboxAnchor to match the button. The Select list now sets its menu variables on SelectContent instead of its viewport, so a class such as [--menu-item-height:2.5rem] on SelectContent reaches the items. - Input, Textarea, InputFloating, SelectTrigger, ComboboxAnchor and Separator set data-size with the default filled in, and the anchor sets data-variant too. With as-child, the anchor leaves the button's own data-variant and data-size alone.

  7. registry 0.12.0

    c79028b — The control scale is now a set of tokens: --control-height-*, --control-padding-*, --control-icon-* and --control-gap-* for xs to xl, added to :root by the tokens item. Button, Input, InputFloating, Select, Combobox, InputNumber, TagsInput, PinInput, InputTime, InputGroup, Menu, Tabs, ColorPicker and Pagination read them, so overriding one on :root resizes every control of that size.

    Some sizes that strayed from the scale now follow it. Button icons are 20px at lg and xl instead of 16px, and so are the icons of Toggle, ToggleGroup, Toolbar and Pagination at those sizes. The gap between an icon and its label is 6, 8, 8, 10 and 12px from xs to xl, about half the icon, everywhere that has one: Button and the components built on it (where it was 4, 6, 8, 8 and 8px), Menu items and the Select, Combobox and Command lists (8, 10, 12, 12 and 12px), and Tabs triggers (6, 8, 8, 8 and 10px). Inset and checkbox or radio items move their labels with it, so they stay in line with items that have an icon. Everything else keeps its size.

  8. registry 0.7.0

    07109fb — Toolbar: Toolbar, ToolbarButton, ToolbarLink, ToolbarSeparator, ToolbarToggleGroup and ToolbarToggleItem over Reka UI's toolbar, drawn with Button and ToggleGroup: one tab stop, arrow-key focus, a framed outline or a bare ghost variant.

  9. registry 0.5.0

    d290041 — Add Toggle and ToggleGroup. Toggle is a two-state button with Button's variants, colours and sizes, styled when on by activeVariant and activeColor; ToggleGroup joins toggles like a ButtonGroup, with single or multiple selection and arrow-key navigation. The core colour rules also match [data-state="on"][data-active-color], so an on toggle reads its active colour.

  10. core 0.4.0

    d290041 — Add Toggle and ToggleGroup. Toggle is a two-state button with Button's variants, colours and sizes, styled when on by activeVariant and activeColor; ToggleGroup joins toggles like a ButtonGroup, with single or multiple selection and arrow-key navigation. The core colour rules also match [data-state="on"][data-active-color], so an on toggle reads its active colour.