Skip to main content
LibreChat is joining ClickHouse to power the open-source Agentic Data Stack 🎉 Learn more
LibreChat

Dropdown

Pick one value from a list, optionally with search.

Dropdown is LibreChat's single-value select. In a form, use the field variant, which matches Input. For a menu of actions instead of values, use DropdownPopup.

import { useId, useState } from 'react'
import { Dropdown } from '@librechat/client'

const MODELS = [
  { value: 'gpt-4o', label: 'GPT-4o' },
  { value: 'claude-sonnet', label: 'Claude Sonnet' },
  { value: 'gemini-pro', label: 'Gemini Pro' },
]

export default function DropdownField() {
  const id = useId()
  const [model, setModel] = useState('')
  return (
    <div className="grid w-full max-w-sm gap-2">
      <span id={id} className="text-text-primary text-sm font-medium">
        Model
      </span>
      <Dropdown
        variant="field"
        aria-labelledby={id}
        value={model}
        onChange={setModel}
        placeholder="Choose a model"
        options={MODELS}
      />
    </div>
  )
}

Props

PropTypeDefaultDescription
valuestringThe selected option's value.
onChange(value: string) => voidCalled with the picked option's value.
optionsArray<string | { value, label, icon?, disabled? } | { divider: true }>The choices, in order.
variant'default' | 'field' | 'compact''default'field matches Input in forms; compact fits toolbars.
placeholderstringShown in the secondary tone while nothing is chosen.
searchablebooleanfalseAdds a search field at the top of the list.
aria-labelledbystringPoints at the field's visible label. The selected value is announced with it.
aria-invalidbooleanMarks a field dropdown invalid.
disabledbooleanfalseBlocks opening the list.
portalbooleantrue, or false inside a dialogRenders the list in a portal. Inside a dialog the list stays in the dialog so focus and screen readers can reach it.

Accessibility

The trigger is a combobox that opens a listbox. Name it with aria-labelledby pointing at a visible label, or aria-label when there is none.

KeyAction
Enter, Space or ↓Opens the list
↑ and ↓Move through the options
EnterPicks the active option and closes the list
EscapeCloses the list without changing the value

How is this guide?

On this page