Select 35

PreviousNext

A React Aria Components listbox with single selection for currency options

Docs
shadcn-studiocomponent

Preview

Loading preview…
registry/new-york/components/select/select-35.tsx
'use client'

import { ListBox, ListBoxItem } from 'react-aria-components'

import { Label } from '@/registry/new-york/ui/label'

const listitems = [
  { id: 'usd', label: 'USD (United States Dollar)' },
  { id: 'eur', label: 'EUR (Euro)' },
  { id: 'gbp', label: 'GBP (British Pound)', isDisabled: true },
  { id: 'jpy', label: 'JPY (Japanese Yen)' }
]

const ListboxSingleOptionDemo = () => {
  return (
    <div className='w-full max-w-xs space-y-2'>
      <Label>Listbox with single option selectable</Label>
      <div className='border-input overflow-hidden rounded-md border'>
        <ListBox
          className='bg-background space-y-1 p-1 text-sm shadow-xs transition-[color,box-shadow]'
          aria-label='Select framework'
          selectionMode='single'
          defaultSelectedKeys={['svelte']}
        >
          {listitems.map(item => (
            <ListBoxItem
              key={item.id}
              className='data-[disabled]:text-muted-foreground data-[selected]:bg-accent data-[selected]:text-accent-foreground flex items-center justify-between rounded-sm px-2 py-1.5'
              textValue={item.label}
              isDisabled={item.isDisabled}
            >
              {item.label}
            </ListBoxItem>
          ))}
        </ListBox>
      </div>
      <p className='text-muted-foreground text-xs' role='region' aria-live='polite'>
        Built using{' '}
        <a
          href='https://react-spectrum.adobe.com/react-aria/ListBox.html'
          className='hover:text-primary underline'
          target='_blank'
        >
          React Aria
        </a>
      </p>
    </div>
  )
}

export default ListboxSingleOptionDemo

Installation

npx shadcn@latest add @shadcn-studio/select-35

Usage

import { Select35 } from "@/components/select-35"
<Select35 />