Segment Group

A group of mutually exclusive toggle buttons that function like radio buttons but with a more visual, segmented appearance.

Anatomy

<script>
  import {
    SegmentGroup,
    SegmentGroupRoot,
    SegmentGroupItem,
    SegmentGroupIndicator,
  } from "@saas-ui/svelte/components/segment-group";
</script>

<SegmentGroup.Root defaultValue="weekly">
  <SegmentGroup.Indicator />
  <SegmentGroup.Item value="daily">Daily</SegmentGroup.Item>
  <SegmentGroup.Item value="weekly">Weekly</SegmentGroup.Item>
  <SegmentGroup.Item value="monthly">Monthly</SegmentGroup.Item>
</SegmentGroup.Root>

Examples

Basic Accessibility

Basic segment group with default styling.

Card Accessibility

Example of segment group used within a card component.

Colours Accessibility

Use the colour prop to change the colour of the segment group.

Controlled Accessibility

Use the value and onValueChange props to control the selected value.

Disabled Accessibility

Use the disabled prop to disable the entire segment group.

Disabled Item Accessibility

Use the disabled prop on individual items to disable specific segments.

Icon Only Accessibility

Use icon-only segments with aria-label for accessibility.

Sizes Accessibility

Use the size prop to change the size of the segment group.

With Icon Accessibility

Add icons to segment items for visual enhancement.

Props

Prop Type Default Description
value text - The controlled value of the segment group.
size xs | sm | md | lg md The size of the component.
colour gray | red | orange | yellow | green | teal | blue | cyan | purple | pink | rose gray The colour of the component.
orientation horizontal | vertical horizontal Layout orientation of the segment group.
disabled boolean false Whether the component is disabled.
onPrefetch any - Callback invoked when hovering over an item. Similar to Astro's link prefetching, this allows preloading data before selection.
class text - CSS class to apply to the component.