# Select URL: /lynx/components/select Source: https://github.com/daangn/seed-design/blob/dev/docs/content/lynx/components/select.mdx A component that selects a value from a list in a native overlay by tapping a trigger. Lynx Engine 최소 버전: 3.9 사용 XElement: 사용 가능 버전: @seed-design/lynx-react@0.8.0, @seed-design/lynx-css@0.12.0 ## Preview ```tsx 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 ( ); } ``` ## Installation - npm: npx @seed-design/cli@latest add ui:select - pnpm: pnpm dlx @seed-design/cli@latest add ui:select - yarn: yarn dlx @seed-design/cli@latest add ui:select - bun: bun x @seed-design/cli@latest add ui:select ## Usage `SelectContent` owns the native overlay, position calculation, display lifetime, and scroll viewport for long lists. ```tsx import { SelectContent, SelectGroup, SelectItem, SelectRoot, SelectTrigger, } from "@/components/ui/select"; export function App() { return ( ); } ``` - `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` ### `SelectTrigger` ### `SelectContent` ### `SelectGroup` ### `SelectItem` ## 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`. ```tsx 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 ( ); } ``` ### Groups Group options with `SelectGroup` and display the group title with `label`. From the second group onwards, divider lines are added between groups. ```tsx 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 ( ); } ``` ### 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 `", "`. ```tsx 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 ( ); } ``` ### With Description Add additional description to an option with `description` in `SelectItem`. ```tsx 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 ( ); } ``` ### 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. ```tsx 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 ( } /> } /> } /> } /> ); } ``` ### 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. ```tsx 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 ( } /> } label={ 지하철 가장 빠름 } /> } label={ 자동차 고객지원에 문의 } /> ); } ``` ### 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. ```tsx 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 ( ); } ``` ### 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. ```tsx 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 ( {timeSlots.map((slot) => ( ))} ); } ``` ### 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. ```tsx 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 ( ); } ``` ### Listening to Value Changes You can control the selected value with `value` and `onValueChange`. ```tsx 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(["apple"]); return ( 선택된 값: {value.length > 0 ? value.join(", ") : "없음"} ); } ``` ### Controlled Open State Control the list state with `open` and `onOpenChange`. Use `defaultOpen` to set only the initial state. ```tsx 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 ( setOpen(true)}> 목록 열기 목록 상태: {open ? "열림" : "닫힘"} ); } ``` ### `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`. ```tsx 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(null); const [closeReason, setCloseReason] = useState(null); function handleOpenChange(nextOpen: boolean, details: { reason: string }) { "background only"; setOpen(nextOpen); (nextOpen ? setOpenReason : setCloseReason)(details.reason); } return ( 마지막 열림 이유: {openReason ?? "-"} 마지막 닫힘 이유: {closeReason ?? "-"} ); } ``` ### 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`. ```tsx 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 ( listFormat.format(items.map((item) => item.textValue))} > rest.length > 0 ? `${first?.textValue ?? ""} 외 ${rest.length}개` : first?.textValue } > ); } ``` ### 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. ```tsx 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 ( ); } ``` ### Form Integration Lynx does not have HTML `
` and native `` and `FormData` | Update 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 integration | Currently, 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-controls` | Directly specify the required `accessibility-*` attributes for each trigger and complex item |