Skip to content

Segmented ​

One of a few options side by side in one sunken track, the picked one lifted out of it. It suits two to four short options that change what a view shows.

tsx
import { Segmented } from '@basmilius/react-ui';
tsx
import { useState } from 'react';
import { Columns2, LayoutGrid, List } from 'lucide-react';
import { Segmented } from '@basmilius/react-ui';

type View = 'list' | 'grid' | 'split';

export default function SegmentedDemo() {
    const [view, setView] = useState<View>('list');

    return (
        <Segmented<View>
            label="View"
            value={view}
            onValueChange={setView}
            options={[
                { id: 'list', label: 'List', icon: List },
                { id: 'grid', label: 'Grid', icon: LayoutGrid },
                { id: 'split', label: 'Split', icon: Columns2 }
            ]}
        />
    );
}

The track is a radiogroup and every option a radio, with aria-checked on the picked one. Each option is its own button in the tab order.

Props ​

PropType
valueTRequired.
onValueChange(id: T) => voidRequired.
optionsreadonly SegmentedOption<T>[]Required. { id, label, icon? }, with a Lucide icon drawn at 14 pixels.
labelstringRequired. The accessible name of the group.
disabledboolean
classNamestring
refRef<HTMLDivElement>

SegmentedProps and SegmentedOption are exported types.