Combobox
Windowed List
A combobox for a directory of hundreds of rows: only a window of the first matches is rendered, with an honest "showing N of M" line and a coverage bar below.
- combobox
- long list
- window
- performance
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/combobox-007?lang=en
- AX-1000Подшипник 1
- AX-1001Ремень 2
- AX-1002Фильтр 3
- AX-1003Насос 4
- AX-1004Клапан 5
- AX-1005Втулка 6
- AX-1006Шкив 7
- AX-1007Муфта 8
- AX-1008Прокладка 9
- AX-1009Датчик 10
- AX-1010Реле 11
- AX-1011Шланг 12
- AX-1012Подшипник 13
- AX-1013Ремень 14
- AX-1014Фильтр 15
- AX-1015Насос 16
- AX-1016Клапан 17
- AX-1017Втулка 18
- AX-1018Шкив 19
- AX-1019Муфта 20
- AX-1020Прокладка 21
- AX-1021Датчик 22
- AX-1022Реле 23
- AX-1023Шланг 24
- AX-1024Подшипник 1
- AX-1025Ремень 2
- AX-1026Фильтр 3
- AX-1027Насос 4
- AX-1028Клапан 5
- AX-1029Втулка 6
- AX-1030Шкив 7
- AX-1031Муфта 8
- AX-1032Прокладка 9
- AX-1033Датчик 10
- AX-1034Реле 11
- AX-1035Шланг 12
- AX-1036Подшипник 13
- AX-1037Ремень 14
- AX-1038Фильтр 15
- AX-1039Насос 16
показано 40 из 240narrow the query
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 "combobox-007" (Windowed List) 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/combobox-007.json
Registry item: https://vibeui.ru/r/combobox-007.json
Installs to: components/vibeui/combobox-007.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
A combobox for a directory of hundreds of rows: only a window of the first matches is rendered, with an honest "showing N of M" line and a coverage bar below.
A combobox for a long directory: the DOM holds a window of the first matches, the counter shows the real result size, and PageUp/PageDown jump ten rows at a time. One file, zero dependencies.
## 3. How to use it
import { Combobox007 } from "@/components/vibeui/combobox-007"
<Combobox007
label="Part number"
options={catalog}
visibleLimit={40}
onSelect={(value) => console.log(value)}
/>
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-combobox-007-* palette — do not swap it for your theme tokens
- the cut to visibleLimit: hundreds of rows in the DOM slow scrolling and bloat the accessibility tree
- the "showing N of M" line — without it people assume there are only forty matches and stop searching
- aria-live on the line and aria-describedby on the field: the counter has to be spoken, not only drawn
- the monospaced code in the row: codes of varying width stop being comparable by eye
- the block's own light surface: without it the dark text disappears on the dark catalog card
## 6. You may change
- the directory content through options and the window size through visibleLimit
- the counter hint through hintLabel
- the field caption through label and the placeholder through placeholder
- the accent color through accent and the list height through max-height
## 7. Rules
- This is not virtualization: rows beyond the window are simply not rendered, not recycled while scrolling.
- A row is split on the first space into code and name — another data shape needs another split.
- The filter is linear: at tens of thousands of rows move the search into useDeferredValue or to the server.
- 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/combobox-007.jsonhttps://vibeui.ru/r/combobox-007.jsonКомпонент самодостаточен: один файл, без зависимостей, собственная палитра --vibeui-combobox-007-*. Клиентский: useMemo фильтрует список и режет его до visibleLimit, useState держит запрос, значение и курсор. В DOM попадает не больше visibleLimit строк — это дешёвая замена виртуализации без внешней библиотеки и без замеров высоты. Подпись «показано N из M» лежит в aria-live="polite" и связана с полем через aria-describedby: она объясняет, почему нужного нет на экране. Полоса под списком показывает долю показанного и не несёт текста, поэтому aria-hidden. Клавиатура добавляет PageDown и PageUp — прыжок на десять строк, без него длинный список не пролистать.
Component source
The same file your agent installs. Here in case you would rather copy it by hand.
"use client"
import { useId, useMemo, useRef, useState } from "react"
import type {
ComponentPropsWithoutRef,
CSSProperties,
KeyboardEvent,
} from "react"
export type Combobox007Props = Omit<
ComponentPropsWithoutRef<"div">,
"children" | "onSelect"
> & {
label?: string
placeholder?: string
options?: string[]
visibleLimit?: number
hintLabel?: string
onSelect?: (value: string) => void
accent?: string
}
// Идея компонента: список на сотни строк нельзя рисовать целиком — в DOM
// уезжает мусор, а человек всё равно не листает дальше десятка. Рисуем окно
// из visibleLimit строк и честно подписываем «показано N из M»: подпись
// объясняет, почему нужного нет на экране, и заменяет прокрутку фильтром.
const STYLES = `
:where([data-vibeui-block="combobox-007"]){
--vibeui-combobox-007-bg:oklch(1 0 0);
--vibeui-combobox-007-fg:oklch(0.22 0.012 250);
--vibeui-combobox-007-muted:oklch(0.53 0.012 250);
--vibeui-combobox-007-border:oklch(0.9 0.006 250);
--vibeui-combobox-007-field:oklch(0.98 0.004 250);
--vibeui-combobox-007-active:oklch(0.95 0.02 250);
--vibeui-combobox-007-accent:oklch(0.52 0.13 250);
--vibeui-combobox-007-radius:0.625rem;
--vibeui-combobox-007-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
--vibeui-combobox-007-mono:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
}
[data-vibeui-block="combobox-007"]{
display:flex;flex-direction:column;gap:0.375rem;
width:100%;max-width:22rem;box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-combobox-007-bg);
border:1px solid var(--vibeui-combobox-007-border);
border-radius:calc(var(--vibeui-combobox-007-radius) + 0.25rem);
color:var(--vibeui-combobox-007-fg);
font-family:var(--vibeui-combobox-007-font);
}
[data-vibeui-block="combobox-007"] label{font-size:0.8125rem;font-weight:600}
[data-vibeui-block="combobox-007"] input{
box-sizing:border-box;width:100%;height:2.5rem;padding:0 0.75rem;
border:1px solid var(--vibeui-combobox-007-border);
border-radius:var(--vibeui-combobox-007-radius);
background:var(--vibeui-combobox-007-field);
color:inherit;font:inherit;font-size:0.875rem;
}
[data-vibeui-block="combobox-007"] input::placeholder{color:var(--vibeui-combobox-007-muted)}
[data-vibeui-block="combobox-007"] input:focus-visible{outline:2px solid var(--vibeui-combobox-007-accent);outline-offset:1px;border-color:transparent}
[data-vibeui-block="combobox-007"] [data-part="list"]{
margin:0;padding:0.25rem;list-style:none;max-height:11rem;overflow-y:auto;
border:1px solid var(--vibeui-combobox-007-border);
border-radius:var(--vibeui-combobox-007-radius);
}
[data-vibeui-block="combobox-007"] [data-part="option"]{
display:flex;align-items:center;gap:0.5rem;min-height:1.9rem;padding:0 0.5rem;
border-radius:0.375rem;font-size:0.875rem;cursor:pointer;
}
[data-vibeui-block="combobox-007"] [data-part="option"][data-active="true"]{background:var(--vibeui-combobox-007-active)}
[data-vibeui-block="combobox-007"] [data-part="code"]{
flex:none;font-family:var(--vibeui-combobox-007-mono);font-size:0.72rem;
color:var(--vibeui-combobox-007-accent);
}
[data-vibeui-block="combobox-007"] [data-part="name"]{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
[data-vibeui-block="combobox-007"] [data-part="status"]{
display:flex;align-items:center;justify-content:space-between;gap:0.5rem;
font-size:0.75rem;color:var(--vibeui-combobox-007-muted);
}
[data-vibeui-block="combobox-007"] [data-part="bar"]{
position:relative;height:0.2rem;border-radius:999px;overflow:hidden;
background:var(--vibeui-combobox-007-active);
}
[data-vibeui-block="combobox-007"] [data-part="bar"] span{
display:block;height:100%;border-radius:999px;
background:var(--vibeui-combobox-007-accent);transition:width .2s ease;
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="combobox-007"] *{animation:none!important;transition:none!important}}
`
const PARTS = [
"Подшипник",
"Ремень",
"Фильтр",
"Насос",
"Клапан",
"Втулка",
"Шкив",
"Муфта",
"Прокладка",
"Датчик",
"Реле",
"Шланг",
]
const DEFAULT_OPTIONS = Array.from({ length: 240 }, (_, index) => {
const part = PARTS[index % PARTS.length]
return `AX-${String(1000 + index)} ${part} ${(index % 24) + 1}`
})
/**
* Combobox для длинного справочника: рисуется окно из первых совпадений,
* под списком — честная подпись «показано N из M».
*/
export function Combobox007({
label = "Артикул",
placeholder = "Код или название",
options = DEFAULT_OPTIONS,
visibleLimit = 40,
hintLabel = "уточните запрос",
onSelect,
accent,
className,
style,
...props
}: Combobox007Props) {
const id = useId()
const [query, setQuery] = useState("")
const [value, setValue] = useState("")
const [active, setActive] = useState(0)
const listRef = useRef<HTMLUListElement>(null)
const { rows, total } = useMemo(() => {
const needle = query.trim().toLowerCase()
const found = needle
? options.filter((option) => option.toLowerCase().includes(needle))
: options
return { rows: found.slice(0, visibleLimit), total: found.length }
}, [options, query, visibleLimit])
const palette = {
...(accent ? { "--vibeui-combobox-007-accent": accent } : null),
...style,
} as CSSProperties
const commit = (option: string) => {
setValue(option)
setQuery("")
setActive(0)
onSelect?.(option)
}
const move = (delta: number) => {
if (!rows.length) return
const next = (active + delta + rows.length) % rows.length
setActive(next)
listRef.current?.children[next]?.scrollIntoView({ block: "nearest" })
}
const onKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
if (event.key === "ArrowDown") {
event.preventDefault()
move(1)
} else if (event.key === "ArrowUp") {
event.preventDefault()
move(-1)
} else if (event.key === "PageDown") {
event.preventDefault()
move(10)
} else if (event.key === "PageUp") {
event.preventDefault()
move(-10)
} else if (event.key === "Enter") {
event.preventDefault()
if (rows[active]) commit(rows[active])
} else if (event.key === "Escape") {
event.preventDefault()
setQuery("")
setActive(0)
}
}
const share = total ? Math.round((rows.length / total) * 100) : 0
return (
<>
<style href="vibeui-combobox-007" precedence="medium">
{STYLES}
</style>
<div
{...props}
data-vibeui-block="combobox-007"
className={className}
style={palette}
>
<label htmlFor={`${id}-input`}>{label}</label>
<input
id={`${id}-input`}
type="text"
role="combobox"
autoComplete="off"
placeholder={value || placeholder}
aria-expanded="true"
aria-controls={`${id}-list`}
aria-autocomplete="list"
aria-describedby={`${id}-status`}
aria-activedescendant={
rows[active] ? `${id}-option-${active}` : undefined
}
value={query}
onChange={(event) => {
setQuery(event.target.value)
setActive(0)
}}
onKeyDown={onKeyDown}
/>
<ul
ref={listRef}
id={`${id}-list`}
role="listbox"
aria-label={label}
data-part="list"
>
{rows.map((option, index) => {
const [code, ...rest] = option.split(" ")
return (
<li
key={option}
id={`${id}-option-${index}`}
role="option"
data-part="option"
data-active={index === active}
aria-selected={option === value}
onMouseEnter={() => setActive(index)}
onMouseDown={(event) => {
event.preventDefault()
commit(option)
}}
>
<span data-part="code">{code}</span>
<span data-part="name">{rest.join(" ")}</span>
</li>
)
})}
</ul>
<div data-part="bar" aria-hidden="true">
<span style={{ width: `${share}%` }} />
</div>
<p data-part="status" id={`${id}-status`} aria-live="polite">
<span>
показано {rows.length} из {total}
</span>
{rows.length < total ? <span>{hintLabel}</span> : null}
</p>
</div>
</>
)
}