UIComponentsReact
A bar of a few options of which the reader picks one, the chosen one drawn on a pill that slides to it.
Built on the headless Segment Group.See its API in Docs
Rendered by React 19.3.1
Installation
npx shadcn@4.23.0 add https://hamur.dev/r/react/segment-group.jsonIt also adds utils. The app needs its setup first: Installation.
Usage
Put a SegmentGroupIndicator and one SegmentGroupItem per option inside SegmentGroup. Each Item has a value and its text as its name; the group holds the chosen one in value or defaultValue. Give the SegmentGroup a name (aria-label, aria-labelledby, or a Field label). Arrow keys move between the Items and check them, as in a radio group. orientation, disabled, readOnly, required, name, form and onValueChange come from the headless Segment Group. Use it for a choice that changes a view or a setting; for content panels that change with the choice, use Tabs.
import { SegmentGroup, SegmentGroupIndicator, SegmentGroupItem } from '@/components/ui/segment-group'Examples
The chosen Item is marked by the pill as well as by its text colour (WCAG 1.4.1). The pill's border is at least 3:1 against the track in every preset theme, light and dark (WCAG 1.4.11), and in forced colours the pill takes the system highlight. Every Item is at least 24 by 24 CSS pixels (WCAG 2.5.8) and shows a focus ring (WCAG 2.4.7). The pill moves with a 200ms transition, none under prefers-reduced-motion or while the group resizes. A vertical group stacks its Items, each the full width. This item takes Base UI's component ID as its slug and one name per Base UI part.
API reference
The styled parts pass every prop to the headless part they wrap and add classes. The props, data attributes and keyboard are on Segment Group's API reference.