Autocomplete
Create Option
An empty result becomes an action: the last row creates the label right there instead of sending you to settings.
- autocomplete
- create
- tags
- keyboard
Preview
Use it with AI
- 1. Copy the link.
- 2. Write to your agent in your own words and drop the link into the sentence.
- 3. The agent opens the link and installs the component from the registry.
put this in the header: https://vibeui.ru/c/autocomplete-010?lang=en
- Create «рефакт»
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-010" (Create Option) 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-010.json
Registry item: https://vibeui.ru/r/autocomplete-010.json
Installs to: components/vibeui/autocomplete-010.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
An empty result becomes an action: the last row creates the label right there instead of sending you to settings.
Autocomplete that can create: when a label is missing, the last row adds it on Enter. The create row lives inside the list, not beside it as a button. Zero dependencies, one file, its own palette.
## 3. How to use it
import { Autocomplete010 } from "@/components/vibeui/autocomplete-010"
<Autocomplete010
defaultOptions={["Urgent", "Bug"]}
onChange={(options) => console.log(options)}
/>
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-010-* palette — do not swap it for your theme tokens
- the create row inside the list: arrows never reach a button parked beside it
- hiding the offer on an exact match — duplicate labels help nobody
- echoing the typed text in the create row: people must see what they are about to add
- the colour and plus mark on the create row: it changes data rather than picking from it
- the label counter below — it confirms the new label exists
## 6. You may change
- the starting defaultOptions list
- the label, placeholder and createLabel copy
- the onChange handler — persisting the new label
- the accent through the accent prop
## 7. Rules
- The component only adds to its own state: persistence belongs in onChange.
- Trim whitespace and settle the casing question before creating, or "Bug" and "bug" become two labels.
- Not everyone may create: if the role forbids it, do not render the create row at all.
- 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-010.jsonhttps://vibeui.ru/r/autocomplete-010.jsonКомпонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-autocomplete-010-*. Клиентский: "use client". Строка создания — часть списка, поэтому индекс активной строки считается по matches.length + 1 и до неё доезжают стрелки. Точное совпадение с существующей меткой убирает предложение создать. Плюс нарисован квадратом с двумя псевдоэлементами.
Component source
The same file your agent installs. Here in case you would rather copy it by hand.
"use client"
import { useId, useMemo, useState } from "react"
import type {
ComponentPropsWithoutRef,
CSSProperties,
KeyboardEvent,
} from "react"
export type Autocomplete010Props = Omit<
ComponentPropsWithoutRef<"div">,
"children" | "onChange"
> & {
label?: string
placeholder?: string
defaultOptions?: string[]
defaultQuery?: string
createLabel?: string
onChange?: (options: string[]) => void
accent?: string
}
// Идея компонента: тупик «ничего не нашлось» превращается в действие. Если
// метки нет в списке, последняя строка предлагает завести её прямо здесь —
// иначе человек уходит в настройки, теряет контекст и возвращается не всегда.
// Строка создания — часть списка, а не кнопка сбоку: до неё доезжают стрелки.
const STYLES = `
:where([data-vibeui-block="autocomplete-010"]){
--vibeui-autocomplete-010-bg:oklch(1 0 0);
--vibeui-autocomplete-010-fg:oklch(0.22 0.014 265);
--vibeui-autocomplete-010-muted:oklch(0.52 0.014 265);
--vibeui-autocomplete-010-border:oklch(0.9 0.006 265);
--vibeui-autocomplete-010-field:oklch(0.985 0.002 265);
--vibeui-autocomplete-010-active:oklch(0.95 0.02 265);
--vibeui-autocomplete-010-accent:oklch(0.55 0.17 265);
--vibeui-autocomplete-010-radius:0.625rem;
--vibeui-autocomplete-010-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="autocomplete-010"]{
display:flex;flex-direction:column;gap:0.375rem;
width:100%;max-width:22rem;box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-autocomplete-010-bg);
border:1px solid var(--vibeui-autocomplete-010-border);
border-radius:calc(var(--vibeui-autocomplete-010-radius) + 0.25rem);
color:var(--vibeui-autocomplete-010-fg);
font-family:var(--vibeui-autocomplete-010-font);
}
[data-vibeui-block="autocomplete-010"] label{font-size:0.8125rem;font-weight:600}
[data-vibeui-block="autocomplete-010"] input{
box-sizing:border-box;width:100%;height:2.5rem;padding:0 0.75rem;
border:1px solid var(--vibeui-autocomplete-010-border);
border-radius:var(--vibeui-autocomplete-010-radius);
background:var(--vibeui-autocomplete-010-field);
color:inherit;font:inherit;font-size:0.875rem;
}
[data-vibeui-block="autocomplete-010"] input::placeholder{color:var(--vibeui-autocomplete-010-muted)}
[data-vibeui-block="autocomplete-010"] input:focus-visible{
outline:2px solid var(--vibeui-autocomplete-010-accent);outline-offset:1px;border-color:transparent;
}
[data-vibeui-block="autocomplete-010"] [data-part="list"]{
margin:0;padding:0.25rem;list-style:none;max-height:10rem;overflow-y:auto;
border:1px solid var(--vibeui-autocomplete-010-border);
border-radius:var(--vibeui-autocomplete-010-radius);
background:var(--vibeui-autocomplete-010-bg);
}
[data-vibeui-block="autocomplete-010"] [data-part="option"]{
display:flex;align-items:center;gap:0.5rem;min-height:2rem;padding:0 0.5rem;
border-radius:0.375rem;font-size:0.875rem;cursor:pointer;
}
[data-vibeui-block="autocomplete-010"] [data-part="option"][data-active="true"]{background:var(--vibeui-autocomplete-010-active)}
/* Строка создания отличается плюсом и цветом: она меняет данные, а не
выбирает из них. */
[data-vibeui-block="autocomplete-010"] [data-part="create"]{color:var(--vibeui-autocomplete-010-accent);font-weight:600}
[data-vibeui-block="autocomplete-010"] [data-part="plus"]{
position:relative;flex:none;width:0.875rem;height:0.875rem;
border:1px solid currentColor;border-radius:0.25rem;
}
[data-vibeui-block="autocomplete-010"] [data-part="plus"]::before,
[data-vibeui-block="autocomplete-010"] [data-part="plus"]::after{
content:"";position:absolute;left:50%;top:50%;background:currentColor;
}
[data-vibeui-block="autocomplete-010"] [data-part="plus"]::before{width:0.4375rem;height:1px;margin:-0.5px 0 0 -0.21875rem}
[data-vibeui-block="autocomplete-010"] [data-part="plus"]::after{width:1px;height:0.4375rem;margin:-0.21875rem 0 0 -0.5px}
[data-vibeui-block="autocomplete-010"] [data-part="hint"]{font-size:0.75rem;color:var(--vibeui-autocomplete-010-muted)}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="autocomplete-010"] *{animation:none!important;transition:none!important}}
`
const DEFAULT_OPTIONS = ["Срочно", "Баг", "Дизайн", "Документация", "Идея"]
/**
* Автодополнение с созданием: пустой результат предлагает завести метку.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function Autocomplete010({
label = "Метка",
placeholder = "Найти или создать",
defaultOptions = DEFAULT_OPTIONS,
defaultQuery = "рефакт",
createLabel = "Создать",
onChange,
accent,
className,
style,
...props
}: Autocomplete010Props) {
const id = useId()
const [options, setOptions] = useState(defaultOptions)
const [query, setQuery] = useState(defaultQuery)
const [active, setActive] = useState(0)
const trimmed = query.trim()
const matches = useMemo(() => {
if (!trimmed) return options
return options.filter((option) =>
option.toLowerCase().includes(trimmed.toLowerCase()),
)
}, [options, trimmed])
const exact = options.some(
(option) => option.toLowerCase() === trimmed.toLowerCase(),
)
const canCreate = Boolean(trimmed) && !exact
const rows = canCreate ? matches.length + 1 : matches.length
const palette = {
...(accent ? { "--vibeui-autocomplete-010-accent": accent } : null),
...style,
} as CSSProperties
const create = () => {
const next = [...options, trimmed]
setOptions(next)
setQuery(trimmed)
setActive(0)
onChange?.(next)
}
const onKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
if (!rows) return
if (event.key === "ArrowDown") {
event.preventDefault()
setActive((active + 1) % rows)
} else if (event.key === "ArrowUp") {
event.preventDefault()
setActive((active - 1 + rows) % rows)
} else if (event.key === "Enter") {
event.preventDefault()
if (canCreate && active === matches.length) create()
else if (matches[active]) setQuery(matches[active])
}
}
return (
<>
<style href="vibeui-autocomplete-010" precedence="medium">
{STYLES}
</style>
<div
{...props}
data-vibeui-block="autocomplete-010"
className={className}
style={palette}
>
<label htmlFor={id}>{label}</label>
<input
id={id}
type="text"
role="combobox"
autoComplete="off"
placeholder={placeholder}
value={query}
aria-expanded={rows > 0}
aria-controls={`${id}-list`}
aria-autocomplete="list"
onChange={(event) => {
setQuery(event.target.value)
setActive(0)
}}
onKeyDown={onKeyDown}
/>
<ul
id={`${id}-list`}
role="listbox"
aria-label={label}
data-part="list"
>
{matches.map((option, index) => (
<li
key={option}
role="option"
data-part="option"
data-active={index === active}
aria-selected={index === active}
onMouseEnter={() => setActive(index)}
onMouseDown={(event) => {
event.preventDefault()
setQuery(option)
}}
>
{option}
</li>
))}
{canCreate ? (
<li
role="option"
data-part="option"
data-create="true"
data-active={active === matches.length}
aria-selected={active === matches.length}
onMouseEnter={() => setActive(matches.length)}
onMouseDown={(event) => {
event.preventDefault()
create()
}}
>
<span data-part="plus" aria-hidden="true" />
<span data-part="create">
{createLabel} «{trimmed}»
</span>
</li>
) : null}
</ul>
<span data-part="hint">
Меток: {options.length}. Enter выбирает строку под курсором
</span>
</div>
</>
)
}