{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "native-datalist-autocomplete",
  "title": "Native Datalist Autocomplete",
  "description": "A text input that uses the browser's own datalist for suggestions, so there is no popup to build, mobile keyboards show their native picker, and free text is always allowed. Use this when a light suggestion list is enough.",
  "registryDependencies": [
    "input"
  ],
  "files": [
    {
      "path": "registry/patterns/native-datalist-autocomplete/native-datalist-autocomplete.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { Input } from \"@/components/ui/input\"\n\nexport type DatalistOption = string | { value: string; label?: string }\n\nconst valueOf = (o: DatalistOption) => (typeof o === \"string\" ? o : o.value)\nconst labelOf = (o: DatalistOption) =>\n  typeof o === \"string\" ? undefined : o.label\n\nexport interface NativeDatalistAutocompleteProps {\n  options: DatalistOption[]\n  value?: string\n  defaultValue?: string\n  onValueChange?: (value: string) => void\n  /** Runs when the text equals one of the options, ignoring case. */\n  onOptionSelect?: (option: DatalistOption) => void\n  label: string\n  hint?: string\n  placeholder?: string\n  className?: string\n}\n\nexport function NativeDatalistAutocomplete({\n  options,\n  value,\n  defaultValue = \"\",\n  onValueChange,\n  onOptionSelect,\n  label,\n  hint,\n  placeholder,\n  className,\n}: NativeDatalistAutocompleteProps) {\n  const [inner, setInner] = React.useState(defaultValue)\n  const text = value ?? inner\n  const id = React.useId()\n\n  return (\n    <div className={cn(\"flex w-full flex-col gap-1.5\", className)}>\n      <label htmlFor={id} className=\"text-sm font-medium\">\n        {label}\n      </label>\n      <Input\n        id={id}\n        type=\"text\"\n        list={`${id}-list`}\n        autoComplete=\"off\"\n        placeholder={placeholder}\n        aria-describedby={`${id}-hint`}\n        value={text}\n        onChange={(event) => {\n          const next = event.target.value\n          setInner(next)\n          onValueChange?.(next)\n          const hit = options.find(\n            (o) => valueOf(o).toLowerCase() === next.toLowerCase()\n          )\n          if (hit) onOptionSelect?.(hit)\n        }}\n      />\n      <datalist id={`${id}-list`}>\n        {options.map((o) => (\n          <option key={valueOf(o)} value={valueOf(o)} label={labelOf(o)} />\n        ))}\n      </datalist>\n      <p id={`${id}-hint`} className=\"text-muted-foreground text-xs\">\n        {hint ? `${hint} ` : \"\"}\n        {options.length} suggestions; you can also type your own.\n      </p>\n    </div>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "type": "registry:block"
}