Hulian UIv0.93.5413 components0 components
  • Start
  • Components
  • Blocks
  • Pages
  • Demos
  • Changelog
ChineseEnglish
  • ComponentsComponents
  • ThemeTheme

Buttons

  • Button
  • ShimmerButton
  • InteractiveHoverButton
  • RainbowButton
  • PulsatingButton
  • RippleButton
  • ButtonGroup
  • SocialButton

Basic Inputs

  • Input
  • Textarea
  • CellEditor
  • Select
  • Checkbox
  • CheckboxGroup
  • Radio
  • Switch
  • Toggle
  • Segmented
  • Slider
  • NumberField
  • ElasticSlider

Advanced Inputs

  • MathTextarea
  • QuestionEditor
  • QuestionAnswer
  • MathField
  • SecretField
  • PasswordGenerator
  • Combobox
  • RemoteSelect
  • Listbox
  • Mentions
  • InputOTP
  • Rating
  • Upload
  • RegionSelect
  • ImageCropper
  • ScopeMatrix
  • Transfer
  • Cascader
  • TreeSelect
  • RegionCascader
  • CountrySelect
  • MarkdownEditor
  • Novel editor
  • RichTextEditor
  • CodeEditor
  • IssueReporter
  • ColorPicker
  • ColorField
  • ColorSwatchPicker
  • Choicebox
  • EmojiPicker
  • VoiceRecord
  • IconPicker
  • InspectorPanel

Date and Time

  • Calendar
  • DatePicker
  • DateTimePicker
  • DateRangePicker
  • TimePicker
  • TimeField

Form Frameworks

  • Form
  • ModalForm / DrawerForm
  • ProForm
  • StepsForm
  • LoginForm
  • AuthPanel
  • ClickCaptcha
  • Label
  • Field
  • SearchForm

Segmented

segmented

Selects one option from a compact segmented control with a moving indicator.

Usage

Basic usage

Pass in the items array, defaultValue sets the initial selection segment, and the slider transitions smoothly.

tsx
<Segmented
  items={[
    { value: "day", label: "Day" },
    { value: "week", label: "week" },
    { value: "month", label: "month" },
  ]}
  defaultValue="week"
  aria-label="Period"
/>

Icon segment

label ariaLabel Provides accessible names when using icons.

tsx
<Segmented
  items={[
    { value: "grid", ariaLabel: "Grid View", label: <LayoutGrid className="size-4" /> },
    { value: "list", ariaLabel: "List view", label: <List className="size-4" /> },
    { value: "map", ariaLabel: "Map View", label: <Map className="size-4" /> },
  ]}
  defaultValue="grid"
  aria-label="View"
/>

Logo within paragraph

label can be placed in rich nodes, such as embedding a discount Tag in the billing cycle.

tsx
<Segmented
  items={[
    { value: "monthly", label: "Monthly payment" },
    {
      value: "yearly",
      ariaLabel: "Pay annually and save 2 months",
      label: (
        <>
          Paid annually
          <Tag variant="soft" tone="success" size="sm">Save 2 months</Tag>
        </>
      ),
    },
  ]}
  defaultValue="monthly"
  aria-label="Billing cycle"
/>

Semantic tone

tone takes the same name and the same values as on TabsList: the label of the selected segment picks up a semantic colour while the slider stays a white pill. The neutral default keeps the existing neutral selected state, so passing nothing changes nothing.

tsx
<Segmented
  items={[
    { value: "day", label: "Day" },
    { value: "week", label: "week" },
    { value: "month", label: "month" },
  ]}
  defaultValue="week"
  tone="brand"
  aria-label="Period"
/>

Size

size="sm" is used for compact scenes such as toolbars.

tsx
<>
  <Segmented size="sm" items={periodItems} defaultValue="day" aria-label="Period-Small" />
  <Segmented items={periodItems} defaultValue="day" aria-label="Cycle-Medium" />
</>

Disabled

Single segment disabled skips this item; overall disabled disables all.

tsx
<>
  <Segmented
    items={[
      { value: "a", label: "A" },
      { value: "b", label: "B", disabled: true },
      { value: "c", label: "C" },
    ]}
    defaultValue="a"
    aria-label="Example"
  />
  <Segmented items={periodItems} defaultValue="week" disabled aria-label="Period" />
</>

Pill shape and link segments

shape="pill" makes the track, slider, and segments fully round; when segments set render (such as <a href>) the group becomes a set of links and the selected one gets aria-current="page", for switching language or version.

MediumEN
tsx
<Segmented
  shape="pill"
  size="sm"
  value="zh"
  aria-label="Language"
  items={[
    { value: "zh", label: "ZH", render: <a href="/zh" /> },
    { value: "en", label: "EN", render: <a href="/en" /> },
  ]}
/>

When to use

Use Segmented for two to five mutually exclusive horizontal choices, such as Day/Week/Month, Grid/List/Map, or Monthly/Annual. An indicator highlights the active item, and the selected value is a single string. Use Radio for vertically arranged form choices, Tabs for switching page-level panels, or Select for a larger collapsed set.

Import

ts
import { Segmented } from "@hulianui/ui"

Props

Segmented

NameTypeDefaultDescription
items *SegmentedItem[]-Definitions for the available segments.
valuestring-Selected value in controlled mode.
defaultValuestringFirst non-disabled segmentInitial selected value in uncontrolled mode.
disabledbooleanfalseWhether to disable the entire control.
size"sm"|"md""md"Visual size.
shape"rounded"|"pill""rounded"rounded matches the control radius; pill makes the track, slider, and segments fully rounded (navbars, marketing pages).
tone"brand"|"success"|"warning"|"danger"|"neutral""brand"Semantic colour of the selected segment. Tints the active label under indicator="text" or the leading 6px dot under indicator="dot"; the slider stays a white pill. The default is brand, matching TabsList in Tabs. Pass neutral for the earlier neutral selected state (text-foreground).
indicator"text"|"dot""text"Active indicator mode shared with Tabs (#434). text tints the active label; dot keeps the active label high-contrast (text-foreground font-semibold) with a leading 6px tone dot and dims inactive labels to text-muted-foreground.
equalWidthbooleantrueWhether segments share equal width via grid tracks. Set false for content-sized segments (inline-flex), useful when short and long labels sit inline next to a search input (#434).
classNamestring-Additional class name for the root element.
aria-labelstring-Accessible label for the control when no visible title is present.

SegmentedItem

NameTypeDefaultDescription
value *string-Unique value that identifies the segment and its selected state.
ariaLabelstring-Accessible label for non-text content such as an icon or logo; otherwise screen readers fall back to value.
disabledbooleanfalseWhether to disable this segment.
renderReactElement-Renders this segment as a custom element (usually <a href> or a framework router link), with label as its content. If any segment sets it, the group is treated as a set of links: role="group", the selected segment gets aria-current="page", and arrow-key roving is off. The element's own onClick still fires.

Events

Segmented

EventTypeDescription
onValueChange(value: string) => voidCalled with the newly selected value; selection is mutually exclusive.

Slots

SegmentedItem

SlotTypeDescription
label *ReactNodeSegment content, such as text or an icon.

Example

tsx
<Segmented
  items={[
    { value: "day", label: "Day" },
    { value: "week", label: "Week" },
    { value: "month", label: "Month" },
  ]}
  defaultValue="week"
  aria-label="Period"
/>

Icon-only segments, each with its own ariaLabel:

tsx
<Segmented
  items={[
    { value: "grid", ariaLabel: "Grid view", label: <LayoutGrid className="size-4" /> },
    { value: "list", ariaLabel: "List view", label: <List className="size-4" /> },
  ]}
  defaultValue="grid"
  aria-label="View"
/>

Link segments (switching language or version, where the selected item is the current page), pill-shaped:

tsx
<Segmented
  shape="pill"
  size="sm"
  value="en"
  aria-label="Language"
  items={[
    { value: "zh", label: "ZH", render: <a href="/zh" hrefLang="zh" /> },
    { value: "en", label: "EN", render: <a href="/en" hrefLang="en" /> },
  ]}
/>

Usage guidelines

  • When space runs out, segments shrink and truncate; they never disappear. Each segment is min-w-0 flex-1 truncate, so every option stays visible and clickable at any width. Before 0.27.0 the missing min-w-0 combined with whitespace-nowrap made segments incompressible, the root grew to the sum of all segment labels, and the overflow was clipped by the parent, leaving options that exist but cannot be reached (#114).
  • Compressible is not the same as usable: four CJK segments in 150px are all ellipsis. In narrow containers use Select, or degrade by container width the way InspectorPanel does.
  • When label is an icon, logo, or other non-text node, provide ariaLabel; otherwise screen readers fall back to the raw value.
  • Controlled usage requires value and onValueChange. For uncontrolled state, provide only defaultValue.
  • Segmented is single-select only. Use ToggleGroup when several items may remain active.
  • Only the selected segment uses font-medium; the others use the regular weight (up to 0.74.1 every segment was font-medium).

Related

Input · Textarea · Select · Checkbox · CheckboxGroup · Radio

Playground

<Segmented
  items={[{ value: "day", label: "Day" }, { value: "week", label: "Week" }, { value: "month", label: "month" }]}
  defaultValue="week"
/>
PreviousToggleFormsNextSlider

On this page

  • Usage
  • Documentation
    • When to use
    • Import
    • Props
    • Events
    • Slots
    • Example
    • Usage guidelines
    • Related
  • Playground