HextaUI

Toggle group: Spacing

spacing puts a gap between items on the spacing scale. Outline items with a gap keep their own borders and fills.

import { IconStar } from "@tabler/icons-react"

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

export function ToggleGroupSpacing() {
  return (
    <div className="flex flex-col items-center gap-4">
      <ToggleGroup spacing={1} aria-label="Rating filter" defaultValue={["4"]}>
        {["1", "2", "3", "4", "5"].map((stars) => (
          <ToggleGroupItem key={stars} value={stars}>
            {stars}
            <IconStar />
          </ToggleGroupItem>
        ))}
      </ToggleGroup>
      <ToggleGroup
        multiple
        spacing={2}
        variant="outline"
        size="sm"
        aria-label="Topics"
        defaultValue={["design"]}
      >
        <ToggleGroupItem value="design">Design</ToggleGroupItem>
        <ToggleGroupItem value="engineering">Engineering</ToggleGroupItem>
        <ToggleGroupItem value="research">Research</ToggleGroupItem>
      </ToggleGroup>
    </div>
  )
}

This adds the example as components/examples/toggle-group/spacing.tsx, together with the Toggle group component and the HextaUI theme tokens it needs.

pnpm dlx shadcn@latest add https://hextaui.com/r/toggle-group-spacing.json

To add only the component, follow the Toggle group installation.

Props in this example

The Toggle group props this example sets, from the API reference.

PropTypeDefault
defaultValue
string[]–
multiple
booleanfalse
variantSets every item's variant.
"default" | "outline""default"
sizeSets every item's size.
"default" | "sm" | "lg""default"
spacingGap between items on the spacing scale. 0 joins outline items.
0 | 0.5 | 1 | 1.5 | 2 | 2.5 | 3 | 4 | 5 | 6 | 80
PropTypeDefault
valueIdentifies the item in the group's value.
string–

Every prop is in the Toggle group API reference.

See them all, with keyboard support and accessibility notes, on the Toggle group page.