Lynx

Select

A component that selects a value from a list in a native overlay by tapping a trigger.

Engine ≥ 3.9<overlay>
Available since@seed-design/lynx-react@0.8.0, @seed-design/lynx-css@0.12.0
Loading Lynx example…

Installation

npx @seed-design/cli@latest add ui:select

Usage

SelectContent owns the native overlay, position calculation, display lifetime, and scroll viewport for long lists.

import {
  SelectContent,
  SelectGroup,
  SelectItem,
  SelectRoot,
  SelectTrigger,
} from "@/components/ui/select";

export function App() {
  return (
    <view style={{ width: "240px" }}>
      <SelectRoot defaultValue={["apple"]}>
        <SelectTrigger accessibility-label="Fruit" placeholder="Select a fruit" />
        <SelectContent>
          <SelectGroup>
            <SelectItem value="apple" label="Apple" />
            <SelectItem value="banana" label="Banana" />
            <SelectItem value="cherry" label="Cherry" />
          </SelectGroup>
        </SelectContent>
      </SelectRoot>
    </view>
  );
}
  • SelectRoot manages value/defaultValue and open/defaultOpen. When multiple is set, it maintains the list and toggles selection even when items are tapped.
  • SelectTrigger displays the selected value or placeholder and opens/closes the list on tap. A string label or accessibility-label from SelectRoot is used as the default accessibility name for the trigger.
  • SelectContent scrolls the list so the selected item is visible and positions the list according to trigger width, available screen space, and safe area.
  • SelectGroup groups related items. Divider lines appear between multiple groups, and label creates a group title.
  • SelectItem combines label, optional description, prefix icon, and default checkmark indicator. You can replace the checkmark with selectedIndicator.

For low-level composition, use Root, Trigger, Value, Placeholder, PrefixIcon, SuffixIcon, Content, ScrollArea, Group, GroupLabel, Item, ItemPrefixIcon, ItemBody, ItemLabel, ItemDescription, and ItemIndicator from the Select namespace. The same API is also provided as flat exports with the Select prefix, like SelectRoot and SelectTrigger.

Props

SelectRoot

Prop

Type

label?React.ReactNode
labelWeight?"medium" | "bold" | undefined
indicator?React.ReactNode
showRequiredIndicator?boolean | undefined
description?React.ReactNode
errorMessage?React.ReactNode
fieldRef?React.Ref<NodesRef> | undefined
accessibility-label?string | undefined
value?string[] | undefined
defaultValue?string[] | undefined
onValueChange?((value: string[]) => void) | undefined
multiple?boolean | undefined
open?boolean | undefined
defaultOpen?boolean | undefined
onOpenChange?((open: boolean, details: SelectOpenChangeDetails) => void) | undefined
disabled?boolean | undefined
readOnly?boolean | undefined
invalid?boolean | undefined
required?boolean | undefined
placement?Placement | undefined
gutter?number | undefined
overflowPadding?number | undefined
formatValue?((items: SelectSelectedItem[]) => React.ReactNode) | undefined
size?"medium" | "large" | "responsive" | undefined
style?CSSProperties | undefined
children?React.ReactNode
className?string | undefined

SelectTrigger

Prop

Type

placeholder?React.ReactNode
prefixIcon?React.ReactElement<LynxIconElementProps, string | React.JSXElementConstructor<any>> | undefined
suffixIcon?React.ReactElement<LynxIconElementProps, string | React.JSXElementConstructor<any>> | undefined
style?CSSProperties | undefined
className?string | undefined
bindtap?EventHandler<BaseTouchEvent<Target>> | undefined
main-thread:bindtap?EventHandler<BaseTouchEvent<Element>> | undefined

SelectContent

Prop

Type

style?CSSProperties | undefined
children?React.ReactNode
className?string | undefined

SelectGroup

Prop

Type

label?React.ReactNode
style?CSSProperties | undefined
children?React.ReactNode
className?string | undefined

SelectItem

Prop

Type

labelReact.ReactNode
description?React.ReactNode
selectedIndicator?React.ReactNode
prefixIcon?React.ReactElement<LynxIconElementProps, string | React.JSXElementConstructor<any>> | undefined
disabled?boolean | undefined
readOnly?boolean | undefined
style?CSSProperties | undefined
className?string | undefined
bindtap?EventHandler<BaseTouchEvent<Target>> | undefined
main-thread:bindtap?EventHandler<BaseTouchEvent<Element>> | undefined
valuestring
textValue?string | undefined

Examples

Size

Set the trigger and list size with size. The default is large, and responsive is interpreted as medium if the native runtime screen width is 1280 or more, otherwise large.

Loading Lynx example…

Groups

Group options with SelectGroup and display the group title with label. From the second group onwards, divider lines are added between groups.

Loading Lynx example…

Multiple Selection

When multiple is set, you can deselect a selected option by tapping it again. During multiple selection, the list does not close and the trigger displays the selected textValue connected by default with ", ".

Loading Lynx example…

With Description

Add additional description to an option with description in SelectItem.

Loading Lynx example…

With Prefix Icon

Display an icon before an option with prefixIcon in SelectItem. When a single option is selected, that icon is displayed in the trigger prefix. When there is no selection or multiple options are selected, the prefixIcon fallback from SelectTrigger is used.

Loading Lynx example…

Custom Item Label

You can pass complex JSX to label. When using a complex label, also specify textValue for the string to display on the trigger and the option accessibility name.

Loading Lynx example…

Disabled

disabled in SelectItem disables a specific option, and disabled in SelectRoot disables the entire Select. readOnly also prevents opening the list or changing the selection.

Loading Lynx example…

Long List

The list is displayed at content height including 8px top and bottom padding, with no separate minimum height. The maximum height is 480px and is constrained to fit the remaining space around the trigger and safe area. Scrolling occurs only when content exceeds this height.

When opened, if the selected option is off-screen, it scrolls only as much as needed to make it visible. The scroll position is not changed when selecting an already visible option or when the list is closing.

Loading Lynx example…

Placement

Set the list position with placement. The default is bottom, and if space is insufficient, the native positioner flips to the opposite side or moves within bounds.

Loading Lynx example…

Listening to Value Changes

You can control the selected value with value and onValueChange.

Loading Lynx example…

Controlled Open State

Control the list state with open and onOpenChange. Use defaultOpen to set only the initial state.

Loading Lynx example…

onOpenChange Details

The second argument of onOpenChange provides the reason for the state change. The reason for opening is trigger, and reasons for closing are trigger, itemSelect, interactOutside, and dismiss.

Loading Lynx example…

Custom Value Format

Change the selected value displayed on the trigger with formatValue. The callback receives an array of selected items containing value, label, textValue, and prefixIcon.

Loading Lynx example…

Field Integration

SelectRoot combines with existing Lynx Field and supports label, description, errorMessage, invalid, required, and showRequiredIndicator. When there is an error message, it displays the error message instead of the description.

Loading Lynx example…

Form Integration

Lynx does not have HTML <form> and native <select> submission models. Store the selected value in app state using onValueChange, and put that value in the submission action payload.

React Hook Form

Currently, the Lynx React runtime and this example path do not have React Hook Form integration or dependencies. Connect value/onValueChange and invalid/errorMessage directly to app state and native request actions.

Differences from Web Version

Lynx Select is rendered on a native overlay. It uses native tap, overlay dismissal, accessibility-* attributes, and app state instead of HTML DOM focus and form models.

ItemReactLynx
Trigger compositionasChild combined with DOM buttonUse native SelectTrigger
Position and long listDOM positioner and scroll areaSelectContent owns native overlay, position calculation, and scroll viewport
Open reasonDOM interaction including keyboard/focustrigger, itemSelect, interactOutside, dismiss
Keyboardfocus, typeahead, Escape to closeNot currently supported in Lynx Select
AccessibilityDOM ARIA id connectionsUse accessibility-label from SelectRoot or SelectTrigger and native accessibility attributes of items
Responsive sizeWeb viewport basedUses native runtime width

Lynx Unsupported Features

FeatureWeb EquivalentApp Alternative
Hidden native select, name, form submission<select> and FormDataUpdate app state with onValueChange and put that value in the submission action payload
Browser validationNative form validation with requiredValidate state in the app submission action and control invalid/errorMessage
React Hook Form exampleuseController with HTML form integrationCurrently, the example path has no React Hook Form integration or dependencies, so connect value/onValueChange and app state with request actions
DOM focus, typeahead, keyboard navigationfocus/keyboard APIUse native tap and host accessibility navigation flow
DOM ARIA idaria-describedby, aria-controlsDirectly specify the required accessibility-* attributes for each trigger and complex item

Table of contents