Skip to content

RichSelect

RichSelect -- Custom select with full control over option and value rendering

Default

Usage

tsx
import { RichSelect } from '@tryvienna/ui'

<div className="w-64">
  <RichSelect value={value} onValueChange={setValue} options={FRUIT_OPTIONS} />
</div>

Examples

Default

Default
tsx
<div className="w-64">
  <RichSelect value={value} onValueChange={setValue} options={FRUIT_OPTIONS} />
</div>

Custom Rendering

Custom Rendering
tsx
<div className="w-64">
  <RichSelect
    value={value}
    onValueChange={setValue}
    options={STATUS_OPTIONS}
    renderValue={(opt) => (
      <span className="flex items-center gap-2">
        <span
          className="size-2 rounded-full shrink-0"
          style={{ backgroundColor: opt.color as string }}
        />
        <span className="font-medium">{opt.label}</span>
      </span>
    )}
    renderOption={(opt) => (
      <span className="flex items-center gap-2">
        <span
          className="size-2 rounded-full shrink-0"
          style={{ backgroundColor: opt.color as string }}
        />
        <span className="flex flex-col">
          <span className="font-medium leading-tight">{opt.label}</span>
          <span className="text-xs text-muted-foreground leading-tight mt-1">
            {opt.description as string}
          </span>
        </span>
      </span>
    )}
  />
</div>

Small

Small
tsx
<div className="w-48">
  <RichSelect value={value} onValueChange={setValue} options={FRUIT_OPTIONS} size="sm" />
</div>

Disabled

Disabled
tsx
<div className="w-64">
  <RichSelect value="apple" onValueChange={() => {}} options={FRUIT_OPTIONS} disabled />
</div>

API Reference

RichSelect

PropTypeDefaultDescription
valuestring-Currently selected value
onValueChange(value: string) =&gt; void-Callback when value changes
optionsT[]-Array of options
renderOption(option: T, state: { selected: boolean; focused: boolean }) =&gt; React.ReactNode-Custom renderer for each option in the dropdown
renderValue(option: T) =&gt; React.ReactNode-Custom renderer for the selected value in the trigger
placeholderstring-Placeholder when no value selected
disabledboolean-Disabled state
side'top' | 'bottom'-Dropdown direction
size'sm' | 'default'-Trigger size variant

Data Attributes

Componentdata-slot
RichSelect"rich-select"