# Command

> Searchable combobox using Command inside a Popover, bound via Controller.

A shadcn/ui block from the [@flx](https://ui.flexnative.com) registry, listed on [shadcn.exchange](https://shadcn.exchange/r/flx/rhf-fields-08).

- Page, with a live preview: https://shadcn.exchange/r/flx/rhf-fields-08
- Screenshot: https://abzjhwgwpdpz7ua5.public.blob.vercel-storage.com/shots/flx/rhf-fields-08-light-5ea3ed3d34571f03.png
- Registry item: https://ui.flexnative.com/r/rhf-fields-08.json
- Listed: 2026-10-13, source last changed 2026-10-13

## Install

```bash
npx shadcn@latest add https://ui.flexnative.com/r/rhf-fields-08.json
```

Run it in a project that has shadcn/ui set up. It adds the files below and installs what they depend on.

## Dependencies

- npm packages: `@hookform/resolvers`, `lucide-react`, `react-hook-form`, `sonner`, `zod`
- Registry items: `field`, `command`, `popover`, `button`

## Files

### `registry/forms/react-hook-form/fields/rhf-fields-08.tsx`

```tsx
'use client'

import { useState } from 'react'
import { Controller, useForm } from 'react-hook-form'
import { zodResolver } from '@hookform/resolvers/zod'
import { CheckIcon, ChevronsUpDownIcon } from 'lucide-react'
import { toast } from 'sonner'
import * as z from 'zod'

import { cn } from '@/lib/utils'
import { Button } from '@/components/ui/button'
import {
  Command,
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandList,
} from '@/components/ui/command'
import {
  Field,
  FieldError,
  FieldGroup,
  FieldLabel,
} from '@/components/ui/field'
import {
  Popover,
  PopoverContent,
  PopoverTrigger,
} from '@/components/ui/popover'

const LANGUAGES = [
  { value: 'typescript', label: 'TypeScript' },
  { value: 'rust', label: 'Rust' },
  { value: 'go', label: 'Go' },
  { value: 'python', label: 'Python' },
  { value: 'elixir', label: 'Elixir' },
] as const

const formSchema = z.object({
  language: z.string().min(1, 'Select a language.'),
})

type FormValues = z.infer<typeof formSchema>

export function RhfFields08() {
  const [open, setOpen] = useState(false)
  const form = useForm<FormValues>({
    resolver: zodResolver(formSchema),
    defaultValues: { language: '' },
  })

  function onSubmit(data: FormValues) {
    toast.success('Language selected', { description: data.language })
  }

  return (
    <form
      onSubmit={form.handleSubmit(onSubmit)}
      className="flex w-full max-w-sm flex-col gap-6"
    >
      <FieldGroup>
        <Controller
          control={form.control}
          name="language"
          render={({ field, fieldState }) => {
            const selected = LANGUAGES.find((l) => l.value === field.value)
            return (
              <Field data-invalid={fieldState.invalid}>
                <FieldLabel htmlFor="rhf-fields-08-language">
                  Language
                </FieldLabel>
                <Popover open={open} onOpenChange={setOpen}>
                  <PopoverTrigger
                    render={
                      <Button
                        id="rhf-fields-08-language"
                        type="button"
                        variant="outline"
                        role="combobox"
                        aria-expanded={open}
                        aria-invalid={fieldState.invalid}
                        className="w-full justify-between font-normal"
                      >
                        {selected ? selected.label : 'Select a language'}
                        <ChevronsUpDownIcon className="text-muted-foreground" />
                      </Button>
                    }
                  />
                  <PopoverContent className="w-(--anchor-width) p-0">
                    <Command>
                      <CommandInput placeholder="Search language..." />
                      <CommandList>
                        <CommandEmpty>No language found.</CommandEmpty>
                        <CommandGroup>
                          {LANGUAGES.map((language) => (
                            <CommandItem
                              key={language.value}
                              value={language.value}
                              onSelect={(value) => {
                                field.onChange(value)
                                setOpen(false)
                              }}
                            >
                              {language.label}
                              <CheckIcon
                                className={cn(
                                  'ml-auto',
                                  field.value === language.value
                                    ? 'opacity-100'
                                    : 'opacity-0',
                                )}
                              />
                            </CommandItem>
                          ))}
                        </CommandGroup>
                      </CommandList>
                    </Command>
                  </PopoverContent>
                </Popover>
                {fieldState.invalid && (
                  <FieldError errors={[fieldState.error]} />
                )}
              </Field>
            )
          }}
        />
      </FieldGroup>
      <Button type="submit" size="sm">
        Save
      </Button>
    </form>
  )
}
```
