A component that selects a value from a list in a native overlay by tapping a trigger.
@seed-design/lynx-react@0.8.0, @seed-design/lynx-css@0.12.0
import "./styles" ;
import { Box, VStack, useSeedClassName } from "@seed-design/lynx-react" ;
import {
SelectContent,
SelectGroup,
SelectItem,
SelectRoot,
SelectTrigger,
} from "@/components/ui/select" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-select-root` }>
< VStack className = "select-preview" >
< Box width = "240px" >
< SelectRoot defaultValue = {[ "apple" ]}>
< SelectTrigger accessibility-label = "과일" placeholder = "과일을 선택하세요" />
< SelectContent >
< SelectGroup >
< SelectItem value = "apple" label = "사과" />
< SelectItem value = "banana" label = "바나나" />
< SelectItem value = "cherry" label = "체리" />
</ SelectGroup >
</ SelectContent >
</ SelectRoot >
</ Box >
</ VStack >
</ view >
);
}
npx @seed-design/cli@latest add ui:select pnpm dlx @seed-design/cli@latest add ui:select yarn dlx @seed-design/cli@latest add ui:select bun x @seed-design/cli@latest add ui:select
Install dependencies
npm install @karrotmarket/lynx-monochrome-icon @seed-design/lynx-react yarn add @karrotmarket/lynx-monochrome-icon @seed-design/lynx-react pnpm add @karrotmarket/lynx-monochrome-icon @seed-design/lynx-react bun add @karrotmarket/lynx-monochrome-icon @seed-design/lynx-react Copy the code below and paste it in /**
* @file ui:select
* @requires @seed-design/lynx-react@>=0.8.0 <1.0.0
* @requires @seed-design/lynx-css@>=0.12.0 <1.0.0
* @requires @karrotmarket/lynx-monochrome-icon@>=1.20.0 <2.0.0
**/
import IconCheckmarkFatFill from "@karrotmarket/lynx-monochrome-icon/IconCheckmarkFatFill" ;
import IconChevronDownSmallLine from "@karrotmarket/lynx-monochrome-icon/IconChevronDownSmallLine" ;
import * as React from "@lynx-js/react" ;
import { Field as SeedField, Select as SeedSelect, mergeProps } from "@seed-design/lynx-react" ;
import type { LynxAccessibilityProps, LynxIconElementProps } from "@seed-design/lynx-react" ;
type FieldRootRef = React . ComponentRef < typeof SeedField.Root>;
const SelectAccessibilityLabelContext =
React. createContext < LynxAccessibilityProps [ "accessibility-label" ]>( undefined );
export interface SelectRootProps
extends SeedSelect . RootProps ,
Pick < SeedField . RootProps , "required" | "invalid" | "readOnly" > {
label ?: React . ReactNode ;
labelWeight ?: SeedField . LabelProps [ "weight" ];
indicator ?: React . ReactNode ;
showRequiredIndicator ?: boolean ;
description ?: React . ReactNode ;
errorMessage ?: React . ReactNode ;
fieldRef ?: React . Ref < FieldRootRef >;
"accessibility-label" ?: LynxAccessibilityProps [ "accessibility-label" ];
}
/**
* Field와 Select의 값·열림 상태를 함께 조합합니다. label이 문자열이 아니면
* `accessibility-label`을 `SelectRoot` 또는 `SelectTrigger`에 지정하세요.
*
* @see https://crispy.carrot-soft.tech/lynx/components/select
*/
export const SelectRoot = React. forwardRef < FieldRootRef , SelectRootProps >(
(
{
children,
label,
labelWeight,
indicator,
showRequiredIndicator,
description,
errorMessage,
fieldRef,
"accessibility-label" : accessibilityLabel,
value,
defaultValue,
onValueChange,
multiple,
open,
defaultOpen,
onOpenChange,
disabled,
required,
invalid,
readOnly,
size,
placement,
gutter,
overflowPadding,
formatValue,
... fieldProps
},
ref,
) => {
const mergedRefProps = React. useMemo (
() => mergeProps ({ ref }, { ref: fieldRef }),
[ref, fieldRef],
);
const renderHeader = label != null || indicator != null ;
const renderErrorMessage = invalid && errorMessage != null ;
const renderDescription = description != null && ! renderErrorMessage;
const renderFooter = renderDescription || renderErrorMessage;
const defaultAccessibilityLabel = typeof label === "string" ? label : undefined ;
const resolvedAccessibilityLabel = accessibilityLabel ?? defaultAccessibilityLabel;
return (
< SeedField.Root
{ ... mergedRefProps}
required = {required}
disabled = {disabled}
invalid = {invalid}
readOnly = {readOnly}
{ ... fieldProps}
>
{renderHeader ? (
< SeedField.Header >
< SeedField.Label weight = {labelWeight}>
{label}
{showRequiredIndicator ? < SeedField.RequiredIndicator /> : null }
{indicator != null ? (
< SeedField.IndicatorText >{indicator}</ SeedField.IndicatorText >
) : null }
</ SeedField.Label >
</ SeedField.Header >
) : null }
< SeedSelect.Root
value = {value}
defaultValue = {defaultValue}
onValueChange = {onValueChange}
multiple = {multiple}
open = {open}
defaultOpen = {defaultOpen}
onOpenChange = {onOpenChange}
disabled = {disabled}
required = {required}
invalid = {invalid}
readOnly = {readOnly}
size = {size}
placement = {placement}
gutter = {gutter}
overflowPadding = {overflowPadding}
formatValue = {formatValue}
>
< SelectAccessibilityLabelContext.Provider value = {resolvedAccessibilityLabel}>
{children}
</ SelectAccessibilityLabelContext.Provider >
</ SeedSelect.Root >
{renderFooter ? (
< SeedField.Footer >
{renderDescription ? (
< SeedField.Description >{description}</ SeedField.Description >
) : null }
{renderErrorMessage ? (
< SeedField.ErrorMessage >{errorMessage}</ SeedField.ErrorMessage >
) : null }
</ SeedField.Footer >
) : null }
</ SeedField.Root >
);
},
);
SelectRoot.displayName = "SelectRoot" ;
export interface SelectTriggerProps extends Omit < SeedSelect . TriggerProps , "children" > {
placeholder ?: React . ReactNode ;
prefixIcon ?: React . ReactElement < LynxIconElementProps >;
suffixIcon ?: React . ReactElement < LynxIconElementProps >;
}
/**
* 선택 값 또는 placeholder를 표시하고 탭으로 목록을 열고 닫습니다.
*
* @see https://crispy.carrot-soft.tech/lynx/components/select
*/
export const SelectTrigger = React. forwardRef < unknown , SelectTriggerProps >(
(
{
placeholder,
prefixIcon,
suffixIcon = < IconChevronDownSmallLine />,
"accessibility-label" : accessibilityLabel,
... props
},
ref,
) => {
const rootAccessibilityLabel = React. useContext (SelectAccessibilityLabelContext);
return (
< SeedSelect.Trigger
ref = {ref}
accessibility-label = {accessibilityLabel ?? rootAccessibilityLabel}
{ ... props}
>
< SeedSelect.PrefixIcon fallback = {prefixIcon} />
< SeedSelect.Value />
{placeholder != null ? (
< SeedSelect.Placeholder >{placeholder}</ SeedSelect.Placeholder >
) : null }
< SeedSelect.SuffixIcon icon = {suffixIcon} />
</ SeedSelect.Trigger >
);
},
);
SelectTrigger.displayName = "SelectTrigger" ;
export interface SelectContentProps extends SeedSelect . ContentProps {}
/**
* Native overlay, 위치 계산, 표시 수명과 긴 목록의 scroll viewport를 함께 구성합니다.
* 자식에 별도 Positioner나 ScrollArea를 추가하지 마세요.
*
* @see https://crispy.carrot-soft.tech/lynx/components/select
*/
export const SelectContent = SeedSelect.Content;
export interface SelectGroupProps extends SeedSelect . GroupProps {
label ?: React . ReactNode ;
}
export const SelectGroup = React. forwardRef < unknown , SelectGroupProps >(
({ label , children , ... props }, ref ) => {
return (
< SeedSelect.Group ref = {ref} { ... props}>
{label != null ? < SeedSelect.GroupLabel >{label}</ SeedSelect.GroupLabel > : null }
{children}
</ SeedSelect.Group >
);
},
);
SelectGroup.displayName = "SelectGroup" ;
export interface SelectItemProps extends Omit < SeedSelect . ItemProps , "children" > {
label : React . ReactNode ;
description ?: React . ReactNode ;
selectedIndicator ?: React . ReactNode ;
prefixIcon ?: React . ReactElement < LynxIconElementProps >;
}
/**
* item body, 설명, prefix icon과 선택 indicator를 조합합니다. `selectedIndicator`로
* 기본 checkmark를 바꿀 수 있습니다.
*
* @see https://crispy.carrot-soft.tech/lynx/components/select
*/
export const SelectItem = React. forwardRef < unknown , SelectItemProps >(
(
{
label,
description,
selectedIndicator = < IconCheckmarkFatFill />,
prefixIcon,
"accessibility-label" : accessibilityLabel,
... props
},
ref,
) => {
return (
< SeedSelect.Item
ref = {ref}
accessibility-label = {accessibilityLabel ?? ( typeof label === "string" ? label : undefined )}
prefixIcon = {prefixIcon}
label = {label}
{ ... props}
>
< SeedSelect.ItemPrefixIcon />
< SeedSelect.ItemBody >
< SeedSelect.ItemLabel >{label}</ SeedSelect.ItemLabel >
{description != null ? (
< SeedSelect.ItemDescription >{description}</ SeedSelect.ItemDescription >
) : null }
</ SeedSelect.ItemBody >
< SeedSelect.ItemIndicator selected = {selectedIndicator} />
</ SeedSelect.Item >
);
},
);
SelectItem.displayName = "SelectItem" ;
/**
* This file is a snippet from Crispy, helping you get started quickly with @seed-design/* packages.
* You can extend this snippet however you want.
*/
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.
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
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
style?CSSProperties | undefined
children?React.ReactNode
className?string | undefined
label?React.ReactNode
style?CSSProperties | undefined
children?React.ReactNode
className?string | undefined
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
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.
import "./styles" ;
import { Box, VStack, useSeedClassName } from "@seed-design/lynx-react" ;
import {
SelectContent,
SelectGroup,
SelectItem,
SelectRoot,
SelectTrigger,
} from "@/components/ui/select" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-select-root` }>
< VStack className = "select-preview" gap = "x4" >
< Box width = "240px" >
< SelectRoot size = "large" defaultValue = {[ "apple" ]}>
< SelectTrigger accessibility-label = "과일 (large)" placeholder = "과일 선택" />
< SelectContent >
< SelectGroup >
< SelectItem value = "apple" label = "사과" />
< SelectItem value = "banana" label = "바나나" />
</ SelectGroup >
</ SelectContent >
</ SelectRoot >
</ Box >
< Box width = "240px" >
< SelectRoot size = "medium" defaultValue = {[ "apple" ]}>
< SelectTrigger accessibility-label = "과일 (medium)" placeholder = "과일 선택" />
< SelectContent >
< SelectGroup >
< SelectItem value = "apple" label = "사과" />
< SelectItem value = "banana" label = "바나나" />
</ SelectGroup >
</ SelectContent >
</ SelectRoot >
</ Box >
</ VStack >
</ view >
);
}
Group options with SelectGroup and display the group title with label. From the second group onwards, divider lines are added between groups.
import "./styles" ;
import { Box, VStack, useSeedClassName } from "@seed-design/lynx-react" ;
import {
SelectContent,
SelectGroup,
SelectItem,
SelectRoot,
SelectTrigger,
} from "@/components/ui/select" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-select-root` }>
< VStack className = "select-preview" >
< Box width = "240px" >
< SelectRoot defaultValue = {[ "seoul" ]}>
< SelectTrigger accessibility-label = "지역" placeholder = "지역 선택" />
< SelectContent >
< SelectGroup label = "아시아" >
< SelectItem value = "seoul" label = "서울" />
< SelectItem value = "tokyo" label = "도쿄" />
< SelectItem value = "singapore" label = "싱가포르" />
< SelectItem value = "dubai" label = "두바이" />
</ SelectGroup >
< SelectGroup label = "유럽" >
< SelectItem value = "london" label = "런던" />
< SelectItem value = "paris" label = "파리" />
< SelectItem value = "berlin" label = "베를린" />
</ SelectGroup >
< SelectGroup label = "아메리카" >
< SelectItem value = "new-york" label = "뉴욕" />
< SelectItem value = "sao-paulo" label = "상파울루" />
</ SelectGroup >
</ SelectContent >
</ SelectRoot >
</ Box >
</ VStack >
</ view >
);
}
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 ", ".
import "./styles" ;
import { Box, VStack, useSeedClassName } from "@seed-design/lynx-react" ;
import {
SelectContent,
SelectGroup,
SelectItem,
SelectRoot,
SelectTrigger,
} from "@/components/ui/select" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-select-root` }>
< VStack className = "select-preview" >
< Box width = "240px" >
< SelectRoot multiple defaultValue = {[ "apple" , "cherry" ]}>
< SelectTrigger accessibility-label = "과일" placeholder = "과일 선택" />
< SelectContent >
< SelectGroup >
< SelectItem value = "apple" label = "사과" />
< SelectItem value = "banana" label = "바나나" />
< SelectItem value = "cherry" label = "체리" />
< SelectItem value = "grape" label = "포도" />
</ SelectGroup >
</ SelectContent >
</ SelectRoot >
</ Box >
</ VStack >
</ view >
);
}
Add additional description to an option with description in SelectItem.
import "./styles" ;
import { Box, VStack, useSeedClassName } from "@seed-design/lynx-react" ;
import {
SelectContent,
SelectGroup,
SelectItem,
SelectRoot,
SelectTrigger,
} from "@/components/ui/select" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-select-root` }>
< VStack className = "select-preview" >
< Box width = "280px" >
< SelectRoot defaultValue = {[ "standard" ]}>
< SelectTrigger accessibility-label = "배송 방법" placeholder = "배송 방법 선택" />
< SelectContent >
< SelectGroup >
< SelectItem value = "standard" label = "일반 배송" description = "3-5일 소요" />
< SelectItem value = "express" label = "빠른 배송" description = "1-2일 소요" />
< SelectItem value = "same-day" label = "당일 배송" description = "오늘 도착" />
</ SelectGroup >
</ SelectContent >
</ SelectRoot >
</ Box >
</ VStack >
</ view >
);
}
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.
import "./styles" ;
import IconGlobeLine from "@karrotmarket/lynx-monochrome-icon/IconGlobeLine" ;
import IconLockLine from "@karrotmarket/lynx-monochrome-icon/IconLockLine" ;
import IconPerson2Line from "@karrotmarket/lynx-monochrome-icon/IconPerson2Line" ;
import IconPersonLine from "@karrotmarket/lynx-monochrome-icon/IconPersonLine" ;
import { Box, VStack, useSeedClassName } from "@seed-design/lynx-react" ;
import {
SelectContent,
SelectGroup,
SelectItem,
SelectRoot,
SelectTrigger,
} from "@/components/ui/select" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-select-root` }>
< VStack className = "select-preview" >
< Box width = "280px" >
< SelectRoot >
< SelectTrigger
accessibility-label = "공유 대상"
placeholder = "공유 대상"
prefixIcon = {< IconPerson2Line />}
/>
< SelectContent >
< SelectGroup label = "그룹" >
< SelectItem value = "public" label = "전체 공개" prefixIcon = {< IconGlobeLine />} />
< SelectItem value = "followers" label = "팔로워만" prefixIcon = {< IconLockLine />} />
< SelectItem value = "private" label = "나만" prefixIcon = {< IconPersonLine />} />
</ SelectGroup >
< SelectGroup label = "사람" >
< SelectItem value = "kim" label = "김하늘" />
< SelectItem value = "lee" label = "이하늘" />
</ SelectGroup >
</ SelectContent >
</ SelectRoot >
</ Box >
</ VStack >
</ view >
);
}
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.
import "./styles" ;
import IconCarLine from "@karrotmarket/lynx-monochrome-icon/IconCarLine" ;
import IconFigureBikeLine from "@karrotmarket/lynx-monochrome-icon/IconFigureBikeLine" ;
import IconMetroFrontsideLine from "@karrotmarket/lynx-monochrome-icon/IconMetroFrontsideLine" ;
import { Badge, Box, HStack, VStack, useSeedClassName } from "@seed-design/lynx-react" ;
import {
SelectContent,
SelectGroup,
SelectItem,
SelectRoot,
SelectTrigger,
} from "@/components/ui/select" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-select-root` }>
< VStack className = "select-preview" >
< Box width = "280px" >
< SelectRoot defaultValue = {[ "metro" ]}>
< SelectTrigger accessibility-label = "이동 수단" placeholder = "이동 수단 선택" />
< SelectContent >
< SelectGroup >
< SelectItem value = "bike" label = "자전거" prefixIcon = {< IconFigureBikeLine />} />
< SelectItem
value = "metro"
textValue = "지하철"
prefixIcon = {< IconMetroFrontsideLine />}
label = {
< HStack align = "center" gap = "x1_5" >
< text >지하철</ text >
< Badge variant = "weak" tone = "informative" >
가장 빠름
</ Badge >
</ HStack >
}
/>
< SelectItem
value = "car"
textValue = "자동차"
disabled
prefixIcon = {< IconCarLine />}
label = {
< HStack align = "center" gap = "x1_5" >
< text >자동차</ text >
< Badge variant = "weak" tone = "warning" >
고객지원에 문의
</ Badge >
</ HStack >
}
/>
</ SelectGroup >
</ SelectContent >
</ SelectRoot >
</ Box >
</ VStack >
</ view >
);
}
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.
import "./styles" ;
import { Box, VStack, useSeedClassName } from "@seed-design/lynx-react" ;
import {
SelectContent,
SelectGroup,
SelectItem,
SelectRoot,
SelectTrigger,
} from "@/components/ui/select" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-select-root` }>
< VStack className = "select-preview" gap = "x4" >
< Box width = "240px" >
< SelectRoot defaultValue = {[ "apple" ]}>
< SelectTrigger accessibility-label = "과일" placeholder = "과일 선택" />
< SelectContent >
< SelectGroup >
< SelectItem value = "apple" label = "사과" />
< SelectItem value = "banana" label = "바나나" disabled />
< SelectItem value = "cherry" label = "체리" />
</ SelectGroup >
</ SelectContent >
</ SelectRoot >
</ Box >
< Box width = "240px" >
< SelectRoot disabled defaultValue = {[ "apple" ]}>
< SelectTrigger accessibility-label = "비활성 과일" placeholder = "과일 선택" />
< SelectContent >
< SelectGroup >
< SelectItem value = "apple" label = "사과" />
< SelectItem value = "banana" label = "바나나" />
</ SelectGroup >
</ SelectContent >
</ SelectRoot >
</ Box >
</ VStack >
</ view >
);
}
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.
import "./styles" ;
import { Box, VStack, useSeedClassName } from "@seed-design/lynx-react" ;
import {
SelectContent,
SelectGroup,
SelectItem,
SelectRoot,
SelectTrigger,
} from "@/components/ui/select" ;
const timeSlots = Array. from ({ length: 48 }, ( _ , index ) => {
const hour = String (Math. floor (index / 2 )). padStart ( 2 , "0" );
return `${ hour }:${ index % 2 === 0 ? "00" : "30"}` ;
});
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-select-root` }>
< VStack className = "select-preview" >
< Box width = "240px" >
< SelectRoot defaultValue = {[ "14:00" ]}>
< SelectTrigger accessibility-label = "예약 시간" placeholder = "시간 선택" />
< SelectContent >
< SelectGroup >
{timeSlots. map (( slot ) => (
< SelectItem key = {slot} value = {slot} label = {slot} />
))}
</ SelectGroup >
</ SelectContent >
</ SelectRoot >
</ Box >
</ VStack >
</ view >
);
}
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.
import "./styles" ;
import { Box, VStack, useSeedClassName } from "@seed-design/lynx-react" ;
import {
SelectContent,
SelectGroup,
SelectItem,
SelectRoot,
SelectTrigger,
} from "@/components/ui/select" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-select-root` }>
< VStack className = "select-preview" >
< Box width = "240px" >
< SelectRoot placement = "top" defaultValue = {[ "apple" ]}>
< SelectTrigger accessibility-label = "과일" placeholder = "과일 선택" />
< SelectContent >
< SelectGroup >
< SelectItem value = "apple" label = "사과" />
< SelectItem value = "banana" label = "바나나" />
< SelectItem value = "cherry" label = "체리" />
</ SelectGroup >
</ SelectContent >
</ SelectRoot >
</ Box >
</ VStack >
</ view >
);
}
You can control the selected value with value and onValueChange.
import "./styles" ;
import { useState } from "@lynx-js/react" ;
import { Box, VStack, useSeedClassName } from "@seed-design/lynx-react" ;
import {
SelectContent,
SelectGroup,
SelectItem,
SelectRoot,
SelectTrigger,
} from "@/components/ui/select" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
const [ value , setValue ] = useState < string []>([ "apple" ]);
return (
< view className = { `${ seedClassName } docs-lynx-select-root` }>
< VStack className = "select-preview" gap = "x2" >
< Box width = "240px" >
< SelectRoot value = {value} onValueChange = {setValue}>
< SelectTrigger accessibility-label = "과일" placeholder = "과일 선택" />
< SelectContent >
< SelectGroup >
< SelectItem value = "apple" label = "사과" />
< SelectItem value = "banana" label = "바나나" />
< SelectItem value = "cherry" label = "체리" />
</ SelectGroup >
</ SelectContent >
</ SelectRoot >
</ Box >
< text className = "select-preview__status" >
선택된 값: {value. length > 0 ? value. join ( ", " ) : "없음" }
</ text >
</ VStack >
</ view >
);
}
Control the list state with open and onOpenChange. Use defaultOpen to set only the initial state.
import "./styles" ;
import { useState } from "@lynx-js/react" ;
import { ActionButton, Box, VStack, useSeedClassName } from "@seed-design/lynx-react" ;
import {
SelectContent,
SelectGroup,
SelectItem,
SelectRoot,
SelectTrigger,
} from "@/components/ui/select" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
const [ open , setOpen ] = useState ( false );
return (
< view className = { `${ seedClassName } docs-lynx-select-root` }>
< VStack className = "select-preview" gap = "x2" >
< Box width = "240px" >
< SelectRoot open = {open} onOpenChange = {setOpen} defaultValue = {[ "apple" ]}>
< SelectTrigger accessibility-label = "과일" placeholder = "과일 선택" />
< SelectContent >
< SelectGroup >
< SelectItem value = "apple" label = "사과" />
< SelectItem value = "banana" label = "바나나" />
< SelectItem value = "cherry" label = "체리" />
</ SelectGroup >
</ SelectContent >
</ SelectRoot >
</ Box >
< ActionButton variant = "neutralWeak" disabled = {open} bindtap = {() => setOpen ( true )}>
목록 열기
</ ActionButton >
< text className = "select-preview__status" >목록 상태: {open ? "열림" : "닫힘" }</ text >
</ VStack >
</ view >
);
}
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.
import "./styles" ;
import { useState } from "@lynx-js/react" ;
import { Box, HStack, VStack, useSeedClassName } from "@seed-design/lynx-react" ;
import {
SelectContent,
SelectGroup,
SelectItem,
SelectRoot,
SelectTrigger,
} from "@/components/ui/select" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
const [ open , setOpen ] = useState ( false );
const [ openReason , setOpenReason ] = useState < string | null >( null );
const [ closeReason , setCloseReason ] = useState < string | null >( null );
function handleOpenChange ( nextOpen : boolean , details : { reason : string }) {
"background only" ;
setOpen (nextOpen);
(nextOpen ? setOpenReason : setCloseReason)(details.reason);
}
return (
< view className = { `${ seedClassName } docs-lynx-select-root` }>
< VStack className = "select-preview" gap = "x4" >
< Box width = "240px" >
< SelectRoot open = {open} onOpenChange = {handleOpenChange} defaultValue = {[ "apple" ]}>
< SelectTrigger accessibility-label = "과일" placeholder = "과일 선택" />
< SelectContent >
< SelectGroup >
< SelectItem value = "apple" label = "사과" />
< SelectItem value = "banana" label = "바나나" />
< SelectItem value = "cherry" label = "체리" />
</ SelectGroup >
</ SelectContent >
</ SelectRoot >
</ Box >
< HStack gap = "x4" >
< text className = "select-preview__status" >마지막 열림 이유: {openReason ?? "-" }</ text >
< text className = "select-preview__status" >마지막 닫힘 이유: {closeReason ?? "-" }</ text >
</ HStack >
</ VStack >
</ view >
);
}
Change the selected value displayed on the trigger with formatValue. The callback receives an array of selected items containing value, label, textValue, and prefixIcon.
import "./styles" ;
import { Box, HStack, VStack, useSeedClassName } from "@seed-design/lynx-react" ;
import {
SelectContent,
SelectGroup,
SelectItem,
SelectRoot,
SelectTrigger,
} from "@/components/ui/select" ;
const listFormat = new Intl. ListFormat ( "ko" , { type: "conjunction" });
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-select-root` }>
< VStack className = "select-preview" >
< HStack width = "full" gap = "x4" >
< Box style = {{ flex: 1 }}>
< SelectRoot
multiple
defaultValue = {[ "apple" , "banana" ]}
formatValue = {( items ) => listFormat. format (items. map (( item ) => item.textValue))}
>
< SelectTrigger accessibility-label = "과일" placeholder = "과일 선택" />
< SelectContent >
< SelectGroup >
< SelectItem value = "apple" label = "사과" />
< SelectItem value = "banana" label = "바나나" />
< SelectItem value = "cherry" label = "체리" />
</ SelectGroup >
</ SelectContent >
</ SelectRoot >
</ Box >
< Box style = {{ flex: 1 }}>
< SelectRoot
multiple
defaultValue = {[ "apple" , "banana" , "cherry" ]}
formatValue = {([ first , ... rest ]) =>
rest. length > 0 ? `${ first ?. textValue ?? ""} 외 ${ rest . length }개` : first?.textValue
}
>
< SelectTrigger accessibility-label = "과일" placeholder = "과일 선택" />
< SelectContent >
< SelectGroup >
< SelectItem value = "apple" label = "사과" />
< SelectItem value = "banana" label = "바나나" />
< SelectItem value = "cherry" label = "체리" />
</ SelectGroup >
</ SelectContent >
</ SelectRoot >
</ Box >
</ HStack >
</ VStack >
</ view >
);
}
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.
import "./styles" ;
import { Box, VStack, useSeedClassName } from "@seed-design/lynx-react" ;
import {
SelectContent,
SelectGroup,
SelectItem,
SelectRoot,
SelectTrigger,
} from "@/components/ui/select" ;
export default function Example () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = { `${ seedClassName } docs-lynx-select-root` }>
< VStack className = "select-preview" gap = "x6" >
< Box width = "240px" >
< SelectRoot
label = "과일"
description = "가장 좋아하는 과일을 선택하세요."
defaultValue = {[ "apple" ]}
>
< SelectTrigger placeholder = "과일 선택" />
< SelectContent >
< SelectGroup >
< SelectItem value = "apple" label = "사과" />
< SelectItem value = "banana" label = "바나나" />
< SelectItem value = "cherry" label = "체리" />
</ SelectGroup >
</ SelectContent >
</ SelectRoot >
</ Box >
< Box width = "240px" >
< SelectRoot label = "과일" labelWeight = "bold" invalid errorMessage = "과일을 선택해주세요." >
< SelectTrigger placeholder = "과일 선택" />
< SelectContent >
< SelectGroup >
< SelectItem value = "apple" label = "사과" />
< SelectItem value = "banana" label = "바나나" />
< SelectItem value = "cherry" label = "체리" />
</ SelectGroup >
</ SelectContent >
</ SelectRoot >
</ Box >
</ VStack >
</ view >
);
}
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.
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.
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.
Item React Lynx Trigger composition asChild combined with DOM buttonUse native SelectTrigger Position and long list DOM positioner and scroll area SelectContent owns native overlay, position calculation, and scroll viewportOpen reason DOM interaction including keyboard/focus trigger, itemSelect, interactOutside, dismissKeyboard focus, typeahead, Escape to close Not currently supported in Lynx Select Accessibility DOM ARIA id connections Use accessibility-label from SelectRoot or SelectTrigger and native accessibility attributes of items Responsive size Web viewport based Uses native runtime width
Feature Web Equivalent App Alternative Hidden native select, name, form submission <select> and FormDataUpdate app state with onValueChange and put that value in the submission action payload Browser validation Native form validation with required Validate state in the app submission action and control invalid/errorMessage React Hook Form example useController 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 navigation focus/keyboard API Use native tap and host accessibility navigation flow DOM ARIA id aria-describedby, aria-controlsDirectly specify the required accessibility-* attributes for each trigger and complex item