Lynx

Segmented Control

A component used when selecting one of several options to immediately filter or switch related content.

Engine ≥ 3.6
Available since@seed-design/lynx-react@0.6.0, @seed-design/lynx-css@0.10.0
Loading Lynx example…

Installation

npx @seed-design/cli add ui:segmented-control

Props

SegmentedControl

You must provide at least one of value or defaultValue to display the selected item and Indicator.

Prop

Type

value?string | undefined
defaultValue?string | undefined
disabled?boolean | undefined
onValueChange?((value: string) => void) | undefined
style?CSSProperties | undefined
children?React.ReactNode
className?string | undefined

SegmentedControlItem

Prop

Type

notification?boolean | undefined
bindtap?EventHandler<BaseTouchEvent<Target>> | undefined
main-thread:bindtap?EventHandler<BaseTouchEvent<Element>> | undefined
className?string | undefined
disabled?boolean | undefined
childrenstring | number
style?CSSProperties | undefined
valuestring

Usage

import {
  SegmentedControl,
  SegmentedControlItem,
} from "@/components/ui/segmented-control";

export function App() {
  return (
    <SegmentedControl defaultValue="hot" accessibility-label="Sort criteria">
      <SegmentedControlItem value="hot">Most popular</SegmentedControlItem>
      <SegmentedControlItem value="new">Most recent</SegmentedControlItem>
    </SegmentedControl>
  );
}

The Registry SegmentedControl automatically adds a selection Indicator.

Examples

Disabled

The disabled prop on SegmentedControl disables all items. Individual SegmentedControlItem elements can also be disabled separately.

Loading Lynx example…

Notification

Loading Lynx example…

Long Label

Loading Lynx example…

Fixed Width

You can specify the width using style or className on SegmentedControl.

Loading Lynx example…

Listening to Value Changes

You can detect selection value changes using onValueChange. In Controlled mode, use it together with value.

Loading Lynx example…

Web Version Differences

ItemReact WebLynx
Rendering ElementsHTML label, inputNative view, text
Selection Eventinput changebindtap, exposed state event is onValueChange
AccessibilityARIA radiogroup, radioLynx accessibility-* attributes
IndicatorCSS grid and custom propertyGrid layout and custom property

Unsupported Lynx Features

  • ItemHiddenInput, name, form, inputProps for HTML form submission
  • Keyboard focus and focus-visible interactions
  • invalid state on SegmentedControlItem

Lynx Registry and package do not provide the invalid state. This difference is intentional. If you need error states, display error text near the SegmentedControl in your app and include error content in the accessibility-label.

Table of contents