apps/www/content/docs/components/segmented-control.mdx
import { SegmentGroup } from "@chakra-ui/react"
<SegmentGroup.Root>
<SegmentGroup.Indicator />
<SegmentGroup.Item>
<SegmentGroup.ItemText />
<SegmentGroup.ItemHiddenInput />
</SegmentGroup.Item>
</SegmentGroup.Root>
The SegmentGroup component also provides a set of shortcuts for common use
cases.
The SegmentGroupItems shortcut renders a list of items based on the items
prop.
This works:
<>
{items.map((item) => (
<SegmentGroup.Item key={item.value} value={item.value}>
<SegmentGroup.ItemText>{item.label}</SegmentGroup.ItemText>
<SegmentGroup.ItemHiddenInput />
</SegmentGroup.Item>
))}
</>
This might be more concise, if you don't need to customize the items:
<SegmentGroup.Items items={items} />
Use the size prop to change the size of the segmented control.
Use the value and onValueChange props to control the selected item.
Here's an example of how to use the SegmentedControl with react-hook-form.
By default, the segmented control is horizontal. Set the orientation prop to
vertical to change the orientation of the segmented control.
Use the disabled prop to disable the segmented control.
Use the disabled prop on the item to disable it.
Customize the indicator appearance using CSS variables like
--segment-indicator-bg and --segment-indicator-shadow.
By default, the segment control doesn't support changing the design via the
colorPalette prop. This example shows how to customize the segmented control
to make the colorPalette prop work.
Render the label as a ReactNode to render an icon.
Here's an example of how to use the SegmentedControl within a Card.