Autocomplete

Datalist Field

Suggestions on a native datalist: the browser owns the list and the filtering, and there is no client code at all.

  • autocomplete
  • datalist
  • no-js
  • form

Preview

1440pxHost theme

Use it with AI

  1. 1. Copy the link.
  2. 2. Write to your agent in your own words and drop the link into the sentence.
  3. 3. The agent opens the link and installs the component from the registry.

put this in the header: https://vibeui.ru/c/autocomplete-001?lang=en

Start typing — the browser suggests from the list
Show the full instructions

What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.

# Install and place "autocomplete-001" (Datalist Field) from VibeUI

## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/autocomplete-001.json

Registry item: https://vibeui.ru/r/autocomplete-001.json
Installs to: components/vibeui/autocomplete-001.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.

Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.

## 2. What it is
Suggestions on a native datalist: the browser owns the list and the filtering, and there is no client code at all.

A field with suggestions on a native datalist: the browser renders and filters the list, the component holds no state and survives without JS. Zero dependencies, one file, its own light surface.

## 3. How to use it
import { Autocomplete001 } from "@/components/vibeui/autocomplete-001"

<Autocomplete001
  label="City"
  options={["London", "Berlin"]}
/>

Read the installed file for the full prop list.

## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.

Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)

## 5. Keep exactly as installed
- the local --vibeui-autocomplete-001-* palette — do not swap it for your theme tokens
- the datalist instead of a hand-rolled list: it is announced by screen readers and survives JS being off
- the label/htmlFor and aria-describedby wiring — without it the field is nameless
- the built-in light surface: on a dark page the label would otherwise vanish
- autoComplete="off" on the field: browser history over a datalist shows two lists at once
- the 2.5rem field height — a thumb has to hit it on a phone

## 6. You may change
- the label and placeholder
- the options array — where suggestions come from
- the hint text under the field
- the accent through the accent prop — the focus ring

## 7. Rules
- The dropdown's look belongs to the browser: datalist rows cannot be styled. If you need your own, take autocomplete-002.
- A datalist does not restrict typing: it suggests, it does not constrain.
- Do not hand over huge lists — the browser renders every option at once.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.

## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.

For developers

npx shadcn@latest add https://vibeui.ru/r/autocomplete-001.json
https://vibeui.ru/r/autocomplete-001.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-autocomplete-001-*. Поле связано с <datalist> через list и общий useId, подпись — через htmlFor, подсказка под полем — через aria-describedby. Стрелка нарисована двумя бордюрами, поэтому иконочный пакет не нужен. Серверный компонент: хуков состояния нет.

Component source

The same file your agent installs. Here in case you would rather copy it by hand.

import { useId } from "react"
import type { ComponentPropsWithoutRef, CSSProperties } from "react"

export type Autocomplete001Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "children"
> & {
  label?: string
  hint?: string
  placeholder?: string
  options?: string[]
  accent?: string
}

// Идея компонента: подсказка на нативном datalist — единственный вариант
// автодополнения, который работает без единой строки клиентского кода и
// доживает до пользователя даже с выключенным JS. Список отдаёт браузер, он
// же фильтрует и озвучивает его скринридеру; наш код только рисует поле.
const STYLES = `
:where([data-vibeui-block="autocomplete-001"]){
--vibeui-autocomplete-001-bg:oklch(1 0 0);
--vibeui-autocomplete-001-fg:oklch(0.22 0.014 265);
--vibeui-autocomplete-001-muted:oklch(0.52 0.014 265);
--vibeui-autocomplete-001-border:oklch(0.9 0.006 265);
--vibeui-autocomplete-001-field:oklch(0.985 0.002 265);
--vibeui-autocomplete-001-accent:oklch(0.55 0.17 265);
--vibeui-autocomplete-001-radius:0.625rem;
--vibeui-autocomplete-001-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
/* Собственная светлая подложка: поле обязано читаться и на тёмной странице. */
[data-vibeui-block="autocomplete-001"]{
display:flex;flex-direction:column;gap:0.375rem;
width:100%;max-width:22rem;box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-autocomplete-001-bg);
border:1px solid var(--vibeui-autocomplete-001-border);
border-radius:calc(var(--vibeui-autocomplete-001-radius) + 0.25rem);
color:var(--vibeui-autocomplete-001-fg);
font-family:var(--vibeui-autocomplete-001-font);
}
[data-vibeui-block="autocomplete-001"] label{font-size:0.8125rem;font-weight:600}
[data-vibeui-block="autocomplete-001"] [data-part="field"]{position:relative;display:block}
[data-vibeui-block="autocomplete-001"] input{
box-sizing:border-box;width:100%;height:2.5rem;
padding:0 2.25rem 0 0.75rem;
border:1px solid var(--vibeui-autocomplete-001-border);
border-radius:var(--vibeui-autocomplete-001-radius);
background:var(--vibeui-autocomplete-001-field);
color:inherit;font:inherit;font-size:0.875rem;
}
[data-vibeui-block="autocomplete-001"] input::placeholder{color:var(--vibeui-autocomplete-001-muted)}
[data-vibeui-block="autocomplete-001"] input:focus-visible{
outline:2px solid var(--vibeui-autocomplete-001-accent);outline-offset:1px;border-color:transparent;
}
/* Стрелка нарисована рамкой: иконочный шрифт ради одного треугольника —
   лишняя зависимость, а SVG внутри инпута всё равно не кликабелен. */
[data-vibeui-block="autocomplete-001"] [data-part="caret"]{
position:absolute;right:0.875rem;top:50%;width:0.4375rem;height:0.4375rem;
margin-top:-0.3125rem;pointer-events:none;
border-right:1.5px solid var(--vibeui-autocomplete-001-muted);
border-bottom:1.5px solid var(--vibeui-autocomplete-001-muted);
transform:rotate(45deg);
}
[data-vibeui-block="autocomplete-001"] [data-part="hint"]{font-size:0.75rem;line-height:1.4;color:var(--vibeui-autocomplete-001-muted)}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="autocomplete-001"] *{animation:none!important;transition:none!important}}
`

const DEFAULT_OPTIONS = [
  "Москва",
  "Санкт-Петербург",
  "Новосибирск",
  "Екатеринбург",
  "Казань",
  "Нижний Новгород",
  "Челябинск",
  "Самара",
]

/**
 * Автодополнение на нативном datalist: без клиентского кода.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Autocomplete001({
  label = "Город",
  hint = "Начните вводить — браузер подскажет из списка",
  placeholder = "Например, Казань",
  options = DEFAULT_OPTIONS,
  accent,
  className,
  style,
  ...props
}: Autocomplete001Props) {
  const id = useId()
  const listId = `${id}-list`
  const palette = {
    ...(accent ? { "--vibeui-autocomplete-001-accent": accent } : null),
    ...style,
  } as CSSProperties

  return (
    <>
      <style href="vibeui-autocomplete-001" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="autocomplete-001"
        className={className}
        style={palette}
      >
        <label htmlFor={id}>{label}</label>
        <span data-part="field">
          <input
            id={id}
            list={listId}
            type="text"
            placeholder={placeholder}
            autoComplete="off"
            aria-describedby={hint ? `${id}-hint` : undefined}
          />
          <span data-part="caret" aria-hidden="true" />
        </span>
        <datalist id={listId}>
          {options.map((option) => (
            <option key={option} value={option} />
          ))}
        </datalist>
        {hint ? (
          <span data-part="hint" id={`${id}-hint`}>
            {hint}
          </span>
        ) : null}
      </div>
    </>
  )
}