On this page

Toggle group

Live examples of Toggle group, with the exact Vue file that renders each one.

Every example is a complete Vue file. Copy it into an app that has the registry installed, or open it in StackBlitz.

Filter by type

Each item is on or off; the list shows every type that is on.

ToggleGroupFilter.vue
<script setup lang="ts">
import { ref } from 'vue'
import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group'

// type="multiple": each record type is on or off; the list shows every type that is on.
const shown = ref(['orders', 'refunds'])
</script>

<template>
  <ToggleGroup v-model="shown" type="multiple" variant="outline" aria-label="Show record types">
    <ToggleGroupItem value="orders">Orders</ToggleGroupItem>
    <ToggleGroupItem value="refunds">Refunds</ToggleGroupItem>
    <ToggleGroupItem value="returns">Returns</ToggleGroupItem>
  </ToggleGroup>
</template>

Icon-only items

Each icon is named by its tooltip.

ToggleGroupIcons.vue
<script setup lang="ts">
import { Bold, Italic, Underline } from '@lucide/vue'
import { ref } from 'vue'
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group'

// Icon-only items: the tooltip is each one's name (relationship="label").
const styles = [
  { value: 'bold', label: 'Bold', icon: Bold },
  { value: 'italic', label: 'Italic', icon: Italic },
  { value: 'underline', label: 'Underline', icon: Underline },
]
const on = ref<string[]>(['bold'])
</script>

<template>
  <TooltipProvider>
    <ToggleGroup v-model="on" type="multiple" variant="outline" size="icon" aria-label="Text style">
      <Tooltip v-for="style in styles" :key="style.value" relationship="label">
        <TooltipTrigger as-child>
          <ToggleGroupItem :value="style.value"><component :is="style.icon" /></ToggleGroupItem>
        </TooltipTrigger>
        <TooltipContent>{{ style.label }}</TooltipContent>
      </Tooltip>
    </ToggleGroup>
  </TooltipProvider>
</template>

Separate buttons

Spacing puts the items apart; at most one is on.

Showing every channel
ToggleGroupSpaced.vue
<script setup lang="ts">
import { computed, ref } from 'vue'
import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group'

// spacing 2 (8 px) for separate Subtle buttons. type="single": at most one on, and it can be turned off again.
const channels = [
  { value: 'web', label: 'Online store' },
  { value: 'pos', label: 'Point of sale' },
  { value: 'marketplace', label: 'Marketplace' },
]
const channel = ref('')
const shown = computed(() => channels.find(item => item.value === channel.value)?.label)
</script>

<template>
  <div class="flex flex-col gap-(--bh-space-100)">
    <ToggleGroup v-model="channel" type="single" :spacing="2" size="sm" aria-label="Only one sales channel">
      <ToggleGroupItem v-for="item in channels" :key="item.value" :value="item.value">{{ item.label }}</ToggleGroupItem>
    </ToggleGroup>
    <span class="text-(--bh-color-text-subtle) [font:var(--bh-font-body-small)]">{{ shown ? `Showing ${shown} only` : 'Showing every channel' }}</span>
  </div>
</template>