Wheel Picker A component for selecting one or more values by scrolling items vertically.
@seed-design/react@2.4.0, @seed-design/css@2.6.0
"use client" ;
import { Box, Text, VStack } from "@seed-design/react" ;
import * as React from "react" ;
import { WheelPicker } from "seed-design/ui/wheel-picker" ;
const buildingOptions = Array. from ({ length: 10 }, ( _ , index ) => {
const value = String ( 101 + index);
return { value, label: `Bldg ${ value }` };
});
const unitOptions = Array. from ({ length: 15 }, ( _ , floorIndex ) =>
Array. from ({ length: 4 }, ( _ , lineIndex ) => {
const value = String ((floorIndex + 1 ) * 100 + lineIndex + 1 );
return { value, label: `Unit ${ value }` };
}),
). flat ();
export default function WheelPickerPreview () {
const [{ building , unit }, setAddress ] = React. useState ({
building: "103" ,
unit: "1202" ,
});
const columns = [
{
id: "building" ,
"aria-label" : "Building" ,
options: buildingOptions,
value: building,
onValueChange : ( nextBuilding : string ) =>
setAddress (( current ) => ({ ... current, building: nextBuilding })),
},
{
id: "unit" ,
"aria-label" : "Unit" ,
options: unitOptions,
value: unit,
onValueChange : ( nextUnit : string ) =>
setAddress (( current ) => ({ ... current, unit: nextUnit })),
},
];
return (
< VStack width = "360px" maxWidth = "100%" gap = "x3" align = "center" >
< Box width = "full" >
< WheelPicker aria-label = "Select building and unit" columns = {columns} />
</ Box >
< Text aria-live = "polite" >
Bldg {building}, Unit {unit}
</ Text >
</ VStack >
);
}
npx @seed-design/cli@latest add ui:wheel-picker pnpm dlx @seed-design/cli@latest add ui:wheel-picker yarn dlx @seed-design/cli@latest add ui:wheel-picker bun x @seed-design/cli@latest add ui:wheel-picker
Install dependencies
npm install @seed-design/react yarn add @seed-design/react pnpm add @seed-design/react bun add @seed-design/react Copy the code below and paste it in /**
* @file ui:wheel-picker
* @requires @seed-design/react@^2.4.0
* @requires @seed-design/css@^2.6.0
**/
"use client" ;
import { WheelPicker as SeedWheelPicker } from "@seed-design/react" ;
import * as React from "react" ;
export interface WheelPickerOption {
/** 항목을 식별하고 선택 상태로 주고받는 고유 값입니다. */
value : string ;
/** 항목에 표시할 내용입니다. */
label : React . ReactNode ;
/** React 요소 label을 스크린 리더에서 읽을 문자열입니다. */
ariaLabel ?: string ;
}
export interface WheelPickerColumn
extends Omit < SeedWheelPicker . ColumnProps , "options" > {
/** 컬럼을 식별하는 고유 값입니다. */
id : string ;
/** 컬럼에 표시할 선택 항목입니다. 하나 이상의 항목을 제공해야 합니다. */
options : readonly WheelPickerOption [];
}
export interface WheelPickerProps extends Omit < SeedWheelPicker . RootProps , "children" > {
/** Wheel Picker를 구성하는 컬럼 목록입니다. */
columns : readonly WheelPickerColumn [];
}
function validateOptionLabels ( columns : readonly WheelPickerColumn []) {
if (process.env. NODE_ENV === "production" ) return ;
for ( const column of columns) {
for ( const option of column.options) {
if (React. isValidElement (option.label) && ! option.ariaLabel) {
console. warn (
`WheelPicker: "${ column . id }" 컬럼에서 React 요소 label을 사용하는 option에는 ariaLabel이 필요합니다.` ,
);
}
}
}
}
/**
* 여러 Wheel Picker 컬럼을 데이터 배열로 구성합니다.
*
* @see https://crispy.carrot-soft.tech/react/components/wheel-picker
*/
export const WheelPicker = React. forwardRef < HTMLDivElement , WheelPickerProps >(
({ columns , ... rootProps }, ref ) => {
validateOptionLabels (columns);
return (
< SeedWheelPicker.Root ref = {ref} { ... rootProps}>
{columns. map (({ id , options , ... columnProps }) => (
< SeedWheelPicker.Column key = {id} options = {options} { ... columnProps} />
))}
</ SeedWheelPicker.Root >
);
},
);
WheelPicker.displayName = "WheelPicker" ;
/**
* This file is a snippet from Crispy, helping you get started quickly with @seed-design/* packages.
* You can extend this snippet however you want.
*/
getAriaValueText?(( value : string ) => string) | undefined
"use client" ;
import { Box, Text, VStack, WheelPicker } from "@seed-design/react" ;
import * as React from "react" ;
const options = [ "작게" , "보통" , "크게" ]. map (( label ) => ({ value: label, label }));
export default function WheelPickerPackageApi () {
const [ value , setValue ] = React. useState ( "보통" );
return (
< VStack width = "320px" maxWidth = "100%" gap = "x3" align = "center" >
< Box width = "full" >
< WheelPicker.Root aria-label = "글자 크기 선택" size = "small" >
< WheelPicker.Column
aria-label = "글자 크기"
options = {options}
value = {value}
onValueChange = {setValue}
renderLabel = {( option ) => (
< WheelPicker.ItemLabel >
< Text fontSize = "t5" fontWeight = "medium" >
{option.label}
</ Text >
</ WheelPicker.ItemLabel >
)}
/>
</ WheelPicker.Root >
</ Box >
< Text aria-live = "polite" >선택값: {value}</ Text >
</ VStack >
);
}
The compound API of @seed-design/react is used when combining columns directly. You can adjust the entire or column-level styles with className on Root and each Column. renderLabel replaces the default ItemLabel with a returned element. If you need default spacing and alignment, you can recombine WheelPicker.ItemLabel as shown in the example. Slot style API for internal items and selection indicators is not provided.
onIndexChange is called whenever the center item changes due to user scrolling or tapping. Since it passes the index and value of each item traversed in order even before settling, it can be used for per-item haptics. Handle the final selected value with onValueChange after scrolling settles.
"use client" ;
import { Box, HStack, Text, VStack } from "@seed-design/react" ;
import * as React from "react" ;
import { WheelPicker } from "seed-design/ui/wheel-picker" ;
function ColorDot ({ color } : { color : string }) {
return (
< Box
as = "span"
aria-hidden = "true"
width = "x3"
height = "x3"
borderRadius = "full"
style = {{ backgroundColor: color }}
/>
);
}
const colorOptions = [
{ value: "carrot" , name: "당근색" , color: "#ff6f0f" },
{ value: "blue" , name: "파란색" , color: "#4285f4" },
{ value: "green" , name: "초록색" , color: "#22a06b" },
]. map (({ value , name , color }) => ({
value,
ariaLabel: name,
label : (
< HStack as = "span" gap = "x2" align = "center" >
< ColorDot color = {color} />
< span >{name}</ span >
</ HStack >
),
}));
export default function WheelPickerReactElementLabel () {
const [ value , setValue ] = React. useState ( "carrot" );
return (
< VStack width = "320px" maxWidth = "100%" gap = "x3" align = "center" >
< Box width = "full" >
< WheelPicker
aria-label = "색상 선택"
columns = {[
{
id: "color" ,
"aria-label" : "색상" ,
options: colorOptions,
value,
onValueChange: setValue,
},
]}
/>
</ Box >
< Text aria-live = "polite" >선택값: {value}</ Text >
</ VStack >
);
}
String and number labels are used as-is for accessibility names. If you use React elements as labels, provide ariaLabel for each option. When accessibility text needs to be calculated separately, use getAriaValueText. Internal elements must inherit currentColor, and buttons, links, input elements, and multi-line content should not be included.
import { Box, Text, VStack, WheelPicker } from "@seed-design/react" ;
const options = [ "낮음" , "보통" , "높음" ]. map (( label ) => ({ value: label, label }));
export default function WheelPickerStates () {
return (
< VStack width = "160px" gap = "x2" align = "center" >
< Text >Disabled</ Text >
< Box width = "full" >
< WheelPicker.Root aria-label = "비활성 중요도" disabled >
< WheelPicker.Column aria-label = "중요도" options = {options} defaultValue = "보통" />
</ WheelPicker.Root >
</ Box >
</ VStack >
);
}
disabled prevents both focus and manipulation of the column.
Provide one or more items in options for each column.
The option's value must be unique within the column.
The controlled value must be in the current options.
When a dependent column changes, pass new options and valid value in the same render.
If external value changes while the user is manipulating or waiting to settle, scroll position synchronization for that change is skipped.
Handle loading, error, and empty states outside Wheel Picker.
Wheel Picker does not automatically correct invalid values to the first item or call a correction callback. Configure date calculation, column dependencies, hidden inputs, and confirmation UI on the consuming side.
The entire Wheel Picker is provided as group, and each column as spinbutton. Specify aria-label or aria-labelledby on Root and each Column.
On keyboard, use ArrowUp and ArrowDown to select previous/next items. Home and End move to first/last items. Use Tab to move between columns.