Taster

진단부품톤 고르기
부품 갤러리 / Select menu

Select menu

Form and input

A searchable select with option descriptions and grouped headers, apply-on-confirm for multi select, and a date picker that opens a calendar popover.

내 사이트에서 가져오기

색을 고르면 아래 부품이 그 색으로 바뀝니다.

실제로 돌아가는 부품입니다. 눌러 보고 입력해 보세요.

내 앱에 넣기

  1. 아직 npm 패키지가 없어서 Taster 리포를 받아 그 안의 명령을 씁니다. 내 앱 폴더가 들어 있는 폴더에서 한 번만 받습니다.

    git clone https://github.com/makim-414/taster.git && npm ci --prefix taster/packages/engine
  2. 내 앱 폴더에서 이 부품을 넣습니다. 부품 파일과 토큰 파일이 src/components/taster 에 들어갑니다.

    node ../taster/packages/engine/cli.mjs add blocks/select-menu --from https://taster-six.vercel.app --dir src/components/taster
  3. 부품은 Tailwind 클래스로 그리고, Taster 프리셋이 그 클래스를 토큰에 연결합니다. Tailwind CSS 를 설치하고, tokens.css 를 앱 루트에서 한 번 불러온 뒤, 앱 루트에 이 설정을 둡니다. 프리셋이 없으면 빌드는 되어도 부품이 스타일 없이 나옵니다.

    // tailwind.config.cjs
    module.exports = {
      presets: [require('./src/components/taster/tailwind-preset.cjs')],
      content: ['./index.html', './src/**/*.{ts,tsx}'],
    };

    Tailwind v3 는 이 파일을 그대로 읽습니다. v4 는 Tailwind 를 불러오는 src/ 의 스타일시트 맨 위에 이 두 줄을 넣습니다.

    @import "tailwindcss";
    @config "../tailwind.config.cjs";

    tokens.css 는 :root 에 --bg, --text, --border, --accent 를 정의합니다. 내 앱의 스타일시트가 같은 이름을 뒤에서 다시 정의하면 그쪽 색이 이깁니다. 새 Vite 앱의 스타터 CSS 처럼 그런 변수가 있으면 지우거나 이름을 바꾸세요.

언제 쓰나요

  • Select and comboboxA searchable select with option descriptions and grouped headers, apply-on-confirm for multi select, and a date picker that opens a calendar popover.

정보

설치할 패키지
tailwindcss, @radix-ui/react-select
라이선스
MIT
출처
oyna-ui OSelect by azabroflovski, MIT, https://github.com/azabroflovski/oyna-ui
코드 보기
import * as React from 'react'
import * as SelectPrimitive from '@radix-ui/react-select'
import { cn } from './_cn'

// Select menu: a styled list select for when the native Select is not enough, usually because each
// option carries a dim hint at the end (a code, a shortcut, a unit). The trigger shows the chosen
// label itself, so nothing renders while the list is closed. Built on @radix-ui/react-select.
// Source: React port of oyna-ui's OSelect (https://github.com/azabroflovski/oyna-ui, a Vue SFC on
// reka-ui), as published on 21st.dev.
// Changes: styled with the registry field chrome and popover tokens instead of the --o-* variables
// (no acid green accent, no frosted list), 44px trigger and options on touch (36px on desk),
// invalid uses --destructive, and the chevron is the registry icon stroke.
// Upstream license: MIT, Copyright (c) 2026 azabroflovski. Full text in THIRD_PARTY_NOTICES.md.
//
// Prefer the native Select from blocks/input for plain lists: it is lighter and phones show their
// own picker. Reach for this one when the hint column earns its place.

export interface SelectMenuItem<T extends string = string> {
  value: T
  label: string
  /** A dim note at the end of the option, such as a code or a shortcut. */
  hint?: string
  disabled?: boolean
}

export interface SelectMenuProps<T extends string = string>
  extends Omit<React.ComponentPropsWithoutRef<'button'>, 'value' | 'defaultValue' | 'onChange'> {
  items: readonly SelectMenuItem<T>[]
  placeholder?: string
  disabled?: boolean
  /** Danger ring and aria-invalid. */
  invalid?: boolean
  value?: T
  defaultValue?: T
  onValueChange?: (value: T) => void
}

export function SelectMenu<T extends string = string>({
  items,
  placeholder = 'Select',
  disabled,
  invalid,
  value,
  defaultValue,
  onValueChange,
  className,
  ...attrs
}: SelectMenuProps<T>) {
  const [internal, setInternal] = React.useState<T | undefined>(defaultValue)
  const selected = value ?? internal
  const current = items.find((item) => item.value === selected)

  return (
    <SelectPrimitive.Root
      value={selected}
      onValueChange={(next: string) => {
        setInternal(next as T)
        onValueChange?.(next as T)
      }}
      disabled={disabled}
    >
      <SelectPrimitive.Trigger
        aria-invalid={invalid || undefined}
        className={cn(
          'inline-flex h-11 w-full items-center justify-between gap-2 rounded-md border border-border-input bg-transparent px-3 text-left text-sm text-text outline-none desk:h-9',
          'focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50',
          'aria-[invalid=true]:border-[var(--destructive)] data-[placeholder]:text-text-subtle',
          className,
        )}
        {...attrs}
      >
        <SelectPrimitive.Value placeholder={placeholder}>{current?.label}</SelectPrimitive.Value>
        <svg
          viewBox="0 0 24 24"
          aria-hidden="true"
          className="h-4 w-4 flex-none text-text-muted"
          fill="none"
          stroke="currentColor"
          strokeWidth="var(--icon-stroke, 2)"
          strokeLinecap="round"
          strokeLinejoin="round"
        >
          <path d="m6 9 6 6 6-6" />
        </svg>
      </SelectPrimitive.Trigger>
      <SelectPrimitive.Portal>
        <SelectPrimitive.Content
          position="popper"
          sideOffset={6}
          collisionPadding={8}
          className="z-50 max-h-[var(--radix-select-content-available-height)] min-w-[var(--radix-select-trigger-width)] overflow-hidden rounded-lg border border-border bg-bg-popover p-1 shadow-xl"
        >
          <SelectPrimitive.Viewport>
            {items.map((item) => (
              <SelectPrimitive.Item
                key={item.value}
                value={item.value}
                disabled={item.disabled}
                className={cn(
                  'relative flex min-h-11 cursor-default select-none items-center justify-between gap-6 rounded-md px-2.5 text-sm text-text-muted outline-none desk:min-h-9',
                  'data-[highlighted]:bg-bg-elev data-[highlighted]:text-text data-[state=checked]:text-text',
                  'data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
                )}
              >
                <SelectPrimitive.ItemText>{item.label}</SelectPrimitive.ItemText>
                {item.hint ? <span className="tabular-nums text-caption text-text-subtle">{item.hint}</span> : null}
              </SelectPrimitive.Item>
            ))}
          </SelectPrimitive.Viewport>
        </SelectPrimitive.Content>
      </SelectPrimitive.Portal>
    </SelectPrimitive.Root>
  )
}