GooseUI

Components

Combobox

New

A text field that filters a list of options as you type, following the WAI-ARIA combobox pattern. It picks one value, several values shown as removable chips, or text that matches no option. The list opens in the top layer and sits under the field through CSS anchor positioning, so overflow: hidden on a parent does not cut it. With a name, the value goes into the form through hidden inputs. The icons are inline SVG, there are no dependencies besides React.

Browser Support

Limited availability
4 features
Details
Anchor positioning

Places the list under the field and flips it up when there is no room below. Without it the list is a plain block under the field, inside the page flow.

Your browser:
Popover

Puts the list in the top layer, above dialogs and clipped containers. Used together with anchor positioning only.

Your browser:
@starting-style

Fades the list in when it opens. Without it the list appears at once.

Your browser:
transition-behavior

Fades the list out when it closes. Without it the list disappears at once.

Your browser:

Preview

Next.jsReact, full-stack, Vercel
React RouterFormerly Remix
AstroContent sites, islands
NuxtVue, full-stack
SvelteKitSvelte, full-stack
SolidStartSolid, fine-grained reactivity
Qwik CityResumable apps
GatsbyNo longer actively developed
AngularGoogle, batteries included
Ember.jsConvention over configuration

Value: next. Type “st” or “re”, then ArrowDown, Home/End, Enter, Escape.

Installation

npx shadcn@latest add @gooseui/combobox
pnpm dlx shadcn@latest add @gooseui/combobox
yarn dlx shadcn@latest add @gooseui/combobox
bunx --bun shadcn@latest add @gooseui/combobox

Usage

"use client"

import * as React from "react"
import { Combobox } from "@/components/ui/combobox"

const frameworks = [
  { value: "next", label: "Next.js", description: "React, full-stack" },
  { value: "astro", label: "Astro", description: "Content sites, islands" },
  { value: "nuxt", label: "Nuxt", description: "Vue, full-stack" },
]

export function FrameworkPicker() {
  const [value, setValue] = React.useState("next")
  return (
    <Combobox
      options={frameworks}
      value={value}
      onValueChange={setValue}
      placeholder="Search frameworks…"
      inputProps={{ "aria-label": "Framework" }}
    />
  )
}

Examples

Several values, custom values, form

multiple shows the picked values as chips and keeps the list open after a pick. allowCustomValue adds an “Add” row for text that matches nothing. Options come from ComboboxOption children here, and name sends one hidden input per value.

bugneeds triage
bugSomething isn't working
documentationImprovements to documentation
enhancementNew feature or request
good first issueGood for newcomers
help wantedExtra attention is needed
needs triage
performance
wontfixArchived label

Backspace in the empty field removes the last label. Type a new name and press Enter to create it.

Submit to see FormData
<form action={saveLabels}>
  <Combobox
    multiple
    name="tags"
    allowCustomValue
    defaultValue={["bug", "needs-triage"]}
    placeholder="Add labels…"
  >
    <ComboboxOption value="bug" description="Something isn't working">bug</ComboboxOption>
    <ComboboxOption value="docs" description="Improvements to documentation">documentation</ComboboxOption>
    <ComboboxOption value="needs-triage">needs triage</ComboboxOption>
    <ComboboxOption value="wontfix" disabled>wontfix</ComboboxOption>
  </Combobox>
  <Button type="submit">Save labels</Button>
</form>

Search on the server

filter={false} shows options exactly as you pass them. Control the typed text with inputValue and onInputValueChange, fetch results and show loading while the request runs.

Type to search

Results arrive after a simulated 600 ms request. Value: none

const [text, setText] = React.useState("")
const [value, setValue] = React.useState("")
const { results, loading } = useCitySearch(text) // your fetch with debounce

<Combobox
  options={results}
  filter={false}
  loading={loading}
  loadingMessage="Searching cities…"
  emptyMessage={text ? "No city found" : "Type to search"}
  inputValue={text}
  onInputValueChange={setText}
  value={value}
  onValueChange={setValue}
/>

Your own texts

All visible and announced texts are props. The functions have to come from a client component, as in this page’s demos.

<Combobox
  options={options}
  emptyMessage="Ничего не найдено"
  loadingMessage="Загрузка…"
  addMessage={(query) => <>Добавить «{query}»</>}
  resultsMessage={(count) => `Найдено: ${count}`}
  removeLabel={(label) => `Удалить ${label}`}
/>

Props

PropTypeDefaultDescription
optionsComboboxOptionData[]-Options as data. Ignored when ComboboxOption children are given
childrenComboboxOption[]-ComboboxOption elements, for custom content in a row
multiplebooleanfalsePick several values, shown as removable chips
valuestring | string[]-Selected value (controlled): a string, or an array with multiple
defaultValuestring | string[]-Initial value when uncontrolled
onValueChange(value: string | string[]) => void-Called with the new value or array of values
namestring-Form field name. The value goes into hidden inputs
placeholderstring-Placeholder of the input
disabledbooleanfalseDisables the field
requiredbooleanfalseThe form will not submit while nothing is picked
allowCustomValuebooleanfalseAccept text that matches no option (Enter or the Add row)
inputValuestring-Typed text (controlled)
onInputValueChange(text: string) => void-Called on every keystroke
filterboolean | (option, query) => booleantrueBuilt-in filter by words of the label, your own function, or false for server-side search
loadingbooleanfalseShow a loading row instead of results
loadingMessageReactNode"Loading…"Text of the loading row
emptyMessageReactNode"No results"Text when nothing matches
addMessage(query: string) => ReactNodeAdd “…”Content of the Add row
resultsMessage(count: number) => string"N results"Result count for screen readers
removeLabel(label: string) => string"Remove …"Accessible name of the chip remove button
inputPropsComponentProps<"input">-Props for the inner <input>: id, aria-label, autoFocus…

Components

ComponentDescription
ComboboxThe field, chips, hidden inputs and the list
ComboboxOptionDeclarative option: value, label, description, disabled. Children replace the label in the list

Features

  • Keyboard: arrows, Home/End, Enter, Escape clears the field, Backspace removes the last chip; focus stays in the input
  • Screen readers: role combobox with aria-activedescendant, a listbox and a polite count of results
  • Highlighted matches: typed words are marked in every option label
  • Native forms: hidden inputs with name, required while empty, reset through your own state
  • No positioning script: anchor positioning in CSS; older browsers get a block under the field
  • Reduced motion: the list opens without the fade and slide