Skip to content

    ToggleGroup

    A named group of toggle buttons for one optional choice or several independent options. Arrow keys move focus without changing selection.

    React

    Preview

    Props

    • variant
    • size
    • disabled
    • iconOnly
    • type
    • orientation
    • dir
    • icon
    import { IconAlignCenter, IconAlignLeft, IconAlignRight } from "@tabler/icons-react"
    import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
    
    <ToggleGroup type="single" defaultValue="left" aria-label="Text alignment" className="min-w-0 max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-md)))]">
      <ToggleGroupItem value="left">
        <IconAlignLeft size={16} />
        Left
      </ToggleGroupItem>
      <ToggleGroupItem value="center">
        <IconAlignCenter size={16} />
        Center
      </ToggleGroupItem>
      <ToggleGroupItem value="right">
        <IconAlignRight size={16} />
        Right
      </ToggleGroupItem>
    </ToggleGroup>

    Usage

    When to use

    • Pick one or several related toolbar options, such as alignment or text formatting.
    • Keep a compact set of choices together with arrow-key navigation.

    When not to use

    • One choice must always remain selected. Use RadioGroup.
    • Switching between content panels. Use Tabs.
    • A single independent option. Use Toggle.

    Platform support

    What each platform has, from the spec. A selected platform is highlighted.

    NameWebiOSAndroidNote
    variantYesYesYes
    sizeYesYesYes
    disabledYesYesYes
    iconOnlyYesYesYes
    typeYesDeferredDeferredNot generated for iOS and Android. Deferred on iOS and Android: multiple.
    value of type: multipleYesDeferredDeferred
    valueYesYesYes
    defaultValueYesYesYes
    onValueChangeYesYesYes
    orientationYesYesYes
    dirYesDeferredDeferredNot generated for iOS and Android.
    loopYesDeferredDeferredNot generated for iOS and Android.
    labelNoYesYesOnly on iOS, Android.
    iconNoYesYesOnly on iOS, Android.
    accessibilityLabelNoYesYesOnly on iOS, Android.
    value of keyboard: ArrowLeft, ArrowRightYesDeferredDeferred
    value of keyboard: ArrowUp, ArrowDownYesDeferredDeferred
    value of keyboard: Home, EndYesDeferredDeferred

    Variants

    variant

    Transparent when off, or a surface with a neutral border for outline.

    • defaultdefault

    • outline

    import { IconAlignCenter, IconAlignLeft, IconAlignRight } from "@tabler/icons-react"
    import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
    
    <ToggleGroup type="single" defaultValue="left" aria-label="Text alignment" className="min-w-0 max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-md)))]">
      <ToggleGroupItem value="left">
        <IconAlignLeft size={16} />
        Left
      </ToggleGroupItem>
      <ToggleGroupItem value="center">
        <IconAlignCenter size={16} />
        Center
      </ToggleGroupItem>
      <ToggleGroupItem value="right">
        <IconAlignRight size={16} />
        Right
      </ToggleGroupItem>
    </ToggleGroup>
    <ToggleGroup variant="outline" type="single" defaultValue="left" aria-label="Text alignment" className="min-w-0 max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-md)))]">
      <ToggleGroupItem value="left">
        <IconAlignLeft size={16} />
        Left
      </ToggleGroupItem>
      <ToggleGroupItem value="center">
        <IconAlignCenter size={16} />
        Center
      </ToggleGroupItem>
      <ToggleGroupItem value="right">
        <IconAlignRight size={16} />
        Right
      </ToggleGroupItem>
    </ToggleGroup>

    size

    Control height, text and icon size, the same steps as Button: sm 28px, md 32px (the default), lg 36px, xl 44px with a mouse; on touch md is 36px, lg 44px and xl 48px. Small controls keep a minimum hit area.

    • sm

    • mddefault

    • lg

    • xl

    import { IconAlignCenter, IconAlignLeft, IconAlignRight } from "@tabler/icons-react"
    import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
    
    <ToggleGroup size="sm" type="single" defaultValue="left" aria-label="Text alignment" className="min-w-0 max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-sm)))]">
      <ToggleGroupItem value="left">
        <IconAlignLeft size={16} />
        Left
      </ToggleGroupItem>
      <ToggleGroupItem value="center">
        <IconAlignCenter size={16} />
        Center
      </ToggleGroupItem>
      <ToggleGroupItem value="right">
        <IconAlignRight size={16} />
        Right
      </ToggleGroupItem>
    </ToggleGroup>
    <ToggleGroup type="single" defaultValue="left" aria-label="Text alignment" className="min-w-0 max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-md)))]">
      <ToggleGroupItem value="left">
        <IconAlignLeft size={16} />
        Left
      </ToggleGroupItem>
      <ToggleGroupItem value="center">
        <IconAlignCenter size={16} />
        Center
      </ToggleGroupItem>
      <ToggleGroupItem value="right">
        <IconAlignRight size={16} />
        Right
      </ToggleGroupItem>
    </ToggleGroup>
    <ToggleGroup size="lg" type="single" defaultValue="left" aria-label="Text alignment" className="min-w-0 max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-lg)))]">
      <ToggleGroupItem value="left">
        <IconAlignLeft size={16} />
        Left
      </ToggleGroupItem>
      <ToggleGroupItem value="center">
        <IconAlignCenter size={16} />
        Center
      </ToggleGroupItem>
      <ToggleGroupItem value="right">
        <IconAlignRight size={16} />
        Right
      </ToggleGroupItem>
    </ToggleGroup>
    <ToggleGroup size="xl" type="single" defaultValue="left" aria-label="Text alignment" className="min-w-0 max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-xl)))]">
      <ToggleGroupItem value="left">
        <IconAlignLeft size={20} />
        Left
      </ToggleGroupItem>
      <ToggleGroupItem value="center">
        <IconAlignCenter size={20} />
        Center
      </ToggleGroupItem>
      <ToggleGroupItem value="right">
        <IconAlignRight size={20} />
        Right
      </ToggleGroupItem>
    </ToggleGroup>

    orientation

    Controls layout and the arrow keys used for navigation.

    • horizontaldefault

    • vertical

    import { IconAlignCenter, IconAlignLeft, IconAlignRight } from "@tabler/icons-react"
    import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
    
    <ToggleGroup type="single" defaultValue="left" aria-label="Text alignment" className="min-w-0 max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-md)))]">
      <ToggleGroupItem value="left">
        <IconAlignLeft size={16} />
        Left
      </ToggleGroupItem>
      <ToggleGroupItem value="center">
        <IconAlignCenter size={16} />
        Center
      </ToggleGroupItem>
      <ToggleGroupItem value="right">
        <IconAlignRight size={16} />
        Right
      </ToggleGroupItem>
    </ToggleGroup>
    <ToggleGroup orientation="vertical" type="single" defaultValue="left" aria-label="Text alignment" className="min-w-0 max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-md)))]">
      <ToggleGroupItem value="left">
        <IconAlignLeft size={16} />
        Left
      </ToggleGroupItem>
      <ToggleGroupItem value="center">
        <IconAlignCenter size={16} />
        Center
      </ToggleGroupItem>
      <ToggleGroupItem value="right">
        <IconAlignRight size={16} />
        Right
      </ToggleGroupItem>
    </ToggleGroup>

    Examples

    Optional alignment

    import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
    
    <ToggleGroup type="single" aria-label="Text alignment" defaultValue="left" className="min-w-0 max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-md)))]">
      <ToggleGroupItem value="left">Left</ToggleGroupItem>
      <ToggleGroupItem value="center">Center</ToggleGroupItem>
      <ToggleGroupItem value="right">Right</ToggleGroupItem>
    </ToggleGroup>

    Independent formatting

    import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
    
    <ToggleGroup type="multiple" aria-label="Text formatting" defaultValue={["bold"]} className="min-w-0 max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-md)))]">
      <ToggleGroupItem value="bold">Bold</ToggleGroupItem>
      <ToggleGroupItem value="italic">Italic</ToggleGroupItem>
    </ToggleGroup>

    Vertical view choices

    import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
    
    <ToggleGroup type="single" aria-label="View" orientation="vertical" variant="outline" className="min-w-0 max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-md)))]">
      <ToggleGroupItem value="grid">Grid</ToggleGroupItem>
      <ToggleGroupItem value="list">List</ToggleGroupItem>
    </ToggleGroup>

    Icon-only alignment

    One optional alignment choice. Each icon has an accessible name.

    import { IconAlignCenter, IconAlignLeft, IconAlignRight } from "@tabler/icons-react"
    import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
    
    <ToggleGroup type="single" aria-label="Text alignment" defaultValue="left" className="min-w-0 max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-md)))]">
      <ToggleGroupItem value="left" iconOnly aria-label="Align left">
        <IconAlignLeft size={16} />
      </ToggleGroupItem>
      <ToggleGroupItem value="center" iconOnly aria-label="Align center">
        <IconAlignCenter size={16} />
      </ToggleGroupItem>
      <ToggleGroupItem value="right" iconOnly aria-label="Align right">
        <IconAlignRight size={16} />
      </ToggleGroupItem>
    </ToggleGroup>

    Formatting icons and text

    Multiple formats can stay selected. Underline is unavailable.

    import { IconBold, IconItalic, IconUnderline } from "@tabler/icons-react"
    import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
    
    <ToggleGroup type="multiple" aria-label="Text formatting" variant="outline" defaultValue={["bold"]} className="min-w-0 max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-md)))]">
      <ToggleGroupItem value="bold">
        <IconBold size={16} />
        Bold
      </ToggleGroupItem>
      <ToggleGroupItem value="italic">
        <IconItalic size={16} />
        Italic
      </ToggleGroupItem>
      <ToggleGroupItem value="underline" disabled>
        <IconUnderline size={16} />
        Underline
      </ToggleGroupItem>
    </ToggleGroup>

    Disabled icon selection

    import { IconBold, IconItalic } from "@tabler/icons-react"
    import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
    
    <ToggleGroup type="multiple" aria-label="Locked text formatting" disabled defaultValue={["bold"]} className="min-w-0 max-w-full flex-wrap gap-y-[max(var(--spacing-xs),calc(var(--size-target-min)-var(--size-element-md)))]">
      <ToggleGroupItem value="bold" iconOnly aria-label="Bold">
        <IconBold size={16} />
      </ToggleGroupItem>
      <ToggleGroupItem value="italic" iconOnly aria-label="Italic">
        <IconItalic size={16} />
      </ToggleGroupItem>
    </ToggleGroup>

    Do and don't

    Do

    • Name the group and keep each item label stable.
    • Use single for an optional view choice and multiple for independent formatting options.

    Don't

    • Do not use single when exactly one choice must remain; use RadioGroup.
    • Do not repeat item values within a group.

    Props

    NameTypeValuesDefaultDescription
    variantenumdefault | outlinedefaultTransparent when off, or a surface with a neutral border for outline.
    sizeenumsm | md | lg | xlmdControl height, text and icon size, the same steps as Button: sm 28px, md 32px (the default), lg 36px, xl 44px with a mouse; on touch md is 36px, lg 44px and xl 48px. Small controls keep a minimum hit area.
    disabledboolean-falsePrevents focus and selection and uses disabled colors.
    iconOnlyboolean-falseSet on ToggleGroupItem. Makes the item square. Requires aria-label on an icon-only item.
    type requiredenumsingle | multiple-single takes string values and permits deselection. multiple takes string arrays. Not generated for iOS and Android. Deferred on iOS and Android: multiple.
    valuenode--Controlled selection: a string for single or a string array for multiple. Every item requires its own unique value.
    defaultValuenode--Initial selection when uncontrolled: a string for single or a string array for multiple.
    onValueChangefunction--Receives a string for single or a string array for multiple. Clearing single selection reports an empty string.
    orientationenumhorizontal | verticalhorizontalControls layout and the arrow keys used for navigation.
    direnumltr | rtlltrText direction, inherited when omitted. RTL reverses horizontal arrows. Not generated for iOS and Android.
    loopboolean-trueWraps arrow navigation at either end when true. Not generated for iOS and Android.
    labelnode--Native only, on an item: the content, text or an icon. With iconOnly, pass the icon and name the item with accessibilityLabel. Only on iOS, Android.
    iconnode--Native only, on an item: an icon before the label. Only on iOS, Android.
    accessibilityLabelstring-Native only, on an item: the name read by VoiceOver and TalkBack when the item shows only an icon. Set it with iconOnly, as aria-label is on web. Only on iOS, Android.

    Slots

    NameRequiredDescription
    itemsyesTwo or more ToggleGroupItem, each with a unique value.

    Anatomy

    PartDescription
    rootThe toggle button, transparent by default or a bordered surface in outline. On uses the soft accent pair.
    iconAn optional decorative icon, 16px in sm, md and lg and 20px in xl.
    hitAreaA transparent pseudo-element that extends the button target to size-target-min.
    wrapperThe named group with token spacing, horizontal by default and vertical when requested.

    Accessibility

    Role: radiogroup (single), toolbar (multiple)

    KeysAction
    TabEnters the group at one item, then leaves the group.
    ArrowLeft, ArrowRightMoves focus in a horizontal group, skips disabled items, and respects text direction.
    ArrowUp, ArrowDownMoves focus in a vertical group and skips disabled items.
    Home, EndMoves focus to the first or last enabled item.
    Space, EnterToggles the focused item.
    • A group requires aria-label or aria-labelledby.
    • Single items expose role="radio" and aria-checked. Multiple items expose aria-pressed.
    • Pressing a selected single item clears selection. Use RadioGroup when a choice must remain selected.
    • Items require unique non-empty value strings. Icon-only items require aria-label.
    • Group size and variant are item defaults. An item can override either default.
    • Arrow keys move focus; they do not select. loop defaults to true.

    Install

    npx werewolf-ui add toggle-group

    Run npx werewolf-ui init once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See Installation for requirements and the alternative registry setup.