Combobox

People Picker

A person picker: an initials avatar, a second line with the email and the role, and a search that runs over both lines at once.

  • combobox
  • people
  • avatar
  • search

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/combobox-004?lang=en

  • Анна Ковалёваanna@studio.ru · дизайн
  • Борис Ильинboris@studio.ru · фронтенд
  • Вера Наумоваvera@studio.ru · аналитика
  • Глеб Осиповgleb@studio.ru · бэкенд
  • Дарья Титоваdaria@studio.ru · поддержка
  • Егор Пановegor@studio.ru · инфраструктура
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-004" (People Picker) 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-004.json

Registry item: https://vibeui.ru/r/combobox-004.json
Installs to: components/vibeui/combobox-004.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 person picker: an initials avatar, a second line with the email and the role, and a search that runs over both lines at once.

A people combobox: an initials circle, a name and a second line with email and role, search across both lines. One file, zero dependencies, the avatar color is derived from the name.

## 3. How to use it
import { Combobox004 } from "@/components/vibeui/combobox-004"

<Combobox004
  label="Assignee"
  people={[{ name: "Anna Kovaleva", detail: "anna@studio.io · design" }]}
  defaultValue="Anna Kovaleva"
  onSelect={(name) => console.log(name)}
/>

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-004-* palette — do not swap it for your theme tokens
- searching the second line: half the people remember the email, not the surname
- aria-hidden on the avatar — the initials repeat the name and turn into noise in speech
- overflow:hidden with an ellipsis on both lines: a long email would otherwise stretch the list
- the different weights of the name and the second line — the same grey on both merges into one band
- the block's own light surface: without it the dark text disappears on the dark catalog card

## 6. You may change
- the list content through people and the initial choice through defaultValue
- the field caption through label and the empty text through placeholder
- the empty-result text through emptyLabel
- the check color through accent, the avatar size and the block width

## 7. Rules
- The second line is a single detail string: separate its parts with a spaced dot, otherwise something important gets cut on a phone.
- Initials come from the first two words of the name — single-word handles get one letter.
- The name hash yields 12 hues: in a list of thirty people colors inevitably repeat, so it is not an identifier.
- 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-004.json
https://vibeui.ru/r/combobox-004.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра --vibeui-combobox-004-*. Клиентский: useState держит запрос, выбранное имя и курсор, useMemo фильтрует людей по склейке имени и второй строки. Оттенок аватара считается из имени хешем FNV-1a и приходит в inline-стиле одной переменной --vibeui-combobox-004-hue, из которой oklch собирает фон и цвет текста — так палитра остаётся управляемой и не превращается в набор захардкоженных цветов. Строка выложена flex: аватар фиксированной ширины, двухэтажный текст с overflow:hidden, галочка выбранного прижата margin-left:auto. Роли ARIA полные: role="combobox" с aria-controls и aria-activedescendant на поле, role="listbox" и role="option" с aria-selected на списке.

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 Combobox004Person = {
  name: string
  detail: string
}

export type Combobox004Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "children" | "onSelect"
> & {
  label?: string
  placeholder?: string
  people?: Combobox004Person[]
  emptyLabel?: string
  defaultValue?: string
  onSelect?: (name: string) => void
  accent?: string
}

// Идея компонента: людей выбирают глазами, а не по строке. Строка списка
// двухэтажная — имя и почта, — а слева кружок с инициалами, оттенок которого
// считается из имени. Поиск идёт и по имени, и по второй строке: половина
// людей помнит почту, а не фамилию.
const STYLES = `
:where([data-vibeui-block="combobox-004"]){
--vibeui-combobox-004-bg:oklch(1 0 0);
--vibeui-combobox-004-fg:oklch(0.22 0.014 265);
--vibeui-combobox-004-muted:oklch(0.55 0.014 265);
--vibeui-combobox-004-border:oklch(0.9 0.006 265);
--vibeui-combobox-004-field:oklch(0.985 0.002 265);
--vibeui-combobox-004-active:oklch(0.955 0.012 265);
--vibeui-combobox-004-accent:oklch(0.55 0.15 25);
--vibeui-combobox-004-radius:0.625rem;
--vibeui-combobox-004-hue:265;
--vibeui-combobox-004-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="combobox-004"]{
display:flex;flex-direction:column;gap:0.375rem;
width:100%;max-width:23rem;box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-combobox-004-bg);
border:1px solid var(--vibeui-combobox-004-border);
border-radius:calc(var(--vibeui-combobox-004-radius) + 0.25rem);
color:var(--vibeui-combobox-004-fg);
font-family:var(--vibeui-combobox-004-font);
}
[data-vibeui-block="combobox-004"] label{font-size:0.8125rem;font-weight:600}
[data-vibeui-block="combobox-004"] input{
box-sizing:border-box;width:100%;height:2.5rem;padding:0 0.75rem;
border:1px solid var(--vibeui-combobox-004-border);
border-radius:var(--vibeui-combobox-004-radius);
background:var(--vibeui-combobox-004-field);
color:inherit;font:inherit;font-size:0.875rem;
}
[data-vibeui-block="combobox-004"] input::placeholder{color:var(--vibeui-combobox-004-muted)}
[data-vibeui-block="combobox-004"] input:focus-visible{outline:2px solid var(--vibeui-combobox-004-accent);outline-offset:1px;border-color:transparent}
[data-vibeui-block="combobox-004"] [data-part="list"]{
margin:0;padding:0.25rem;list-style:none;max-height:13rem;overflow-y:auto;
border:1px solid var(--vibeui-combobox-004-border);
border-radius:var(--vibeui-combobox-004-radius);
}
[data-vibeui-block="combobox-004"] [data-part="option"]{
display:flex;align-items:center;gap:0.625rem;
padding:0.4rem 0.5rem;border-radius:0.5rem;cursor:pointer;
}
[data-vibeui-block="combobox-004"] [data-part="option"][data-active="true"]{background:var(--vibeui-combobox-004-active)}
[data-vibeui-block="combobox-004"] [data-part="avatar"]{
display:flex;align-items:center;justify-content:center;flex:none;
width:2rem;height:2rem;border-radius:999px;
font-size:0.75rem;font-weight:700;letter-spacing:0.02em;
background:oklch(0.92 0.06 var(--vibeui-combobox-004-hue));
color:oklch(0.38 0.11 var(--vibeui-combobox-004-hue));
}
[data-vibeui-block="combobox-004"] [data-part="text"]{display:flex;flex-direction:column;min-width:0;gap:0.05rem}
[data-vibeui-block="combobox-004"] [data-part="name"]{
font-size:0.875rem;font-weight:600;line-height:1.2;
overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
}
[data-vibeui-block="combobox-004"] [data-part="detail"]{
font-size:0.75rem;color:var(--vibeui-combobox-004-muted);line-height:1.2;
overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
}
[data-vibeui-block="combobox-004"] [data-part="check"]{
margin-left:auto;flex:none;font-size:0.85rem;font-weight:700;
color:var(--vibeui-combobox-004-accent);
}
[data-vibeui-block="combobox-004"] [data-part="empty"]{padding:0.5rem;font-size:0.8125rem;color:var(--vibeui-combobox-004-muted)}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="combobox-004"] *{animation:none!important;transition:none!important}}
`

const DEFAULT_PEOPLE: Combobox004Person[] = [
  { name: "Анна Ковалёва", detail: "anna@studio.ru · дизайн" },
  { name: "Борис Ильин", detail: "boris@studio.ru · фронтенд" },
  { name: "Вера Наумова", detail: "vera@studio.ru · аналитика" },
  { name: "Глеб Осипов", detail: "gleb@studio.ru · бэкенд" },
  { name: "Дарья Титова", detail: "daria@studio.ru · поддержка" },
  { name: "Егор Панов", detail: "egor@studio.ru · инфраструктура" },
]

function hue(name: string) {
  let hash = 2166136261
  for (const symbol of name) {
    hash ^= symbol.codePointAt(0)!
    hash = Math.imul(hash, 16777619)
  }
  return ((hash >>> 0) % 12) * 30
}

function initials(name: string) {
  return name
    .split(" ")
    .slice(0, 2)
    .map((part) => part.charAt(0).toUpperCase())
    .join("")
}

/**
 * Combobox с людьми: аватар с инициалами, вторая строка с почтой и ролью,
 * поиск по обеим строкам.
 */
export function Combobox004({
  label = "Исполнитель",
  placeholder = "Имя или почта",
  people = DEFAULT_PEOPLE,
  emptyLabel = "Никого не нашлось",
  defaultValue = "Вера Наумова",
  onSelect,
  accent,
  className,
  style,
  ...props
}: Combobox004Props) {
  const id = useId()
  const [query, setQuery] = useState("")
  const [value, setValue] = useState(defaultValue)
  const [active, setActive] = useState(0)
  const listRef = useRef<HTMLUListElement>(null)

  const matches = useMemo(() => {
    const needle = query.trim().toLowerCase()
    if (!needle) return people
    return people.filter((person) =>
      `${person.name} ${person.detail}`.toLowerCase().includes(needle),
    )
  }, [people, query])

  const palette = {
    ...(accent ? { "--vibeui-combobox-004-accent": accent } : null),
    ...style,
  } as CSSProperties

  const commit = (person: Combobox004Person) => {
    setValue(person.name)
    setQuery("")
    setActive(0)
    onSelect?.(person.name)
  }

  const move = (delta: number) => {
    if (!matches.length) return
    const next = (active + delta + matches.length) % matches.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 === "Enter") {
      event.preventDefault()
      if (matches[active]) commit(matches[active])
    } else if (event.key === "Escape") {
      event.preventDefault()
      setQuery("")
    }
  }

  return (
    <>
      <style href="vibeui-combobox-004" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="combobox-004"
        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-activedescendant={
            matches[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"
        >
          {matches.map((person, index) => (
            <li
              key={person.name}
              id={`${id}-option-${index}`}
              role="option"
              data-part="option"
              data-active={index === active}
              aria-selected={person.name === value}
              onMouseEnter={() => setActive(index)}
              onMouseDown={(event) => {
                event.preventDefault()
                commit(person)
              }}
            >
              <span
                data-part="avatar"
                aria-hidden="true"
                style={
                  {
                    "--vibeui-combobox-004-hue": hue(person.name),
                  } as CSSProperties
                }
              >
                {initials(person.name)}
              </span>
              <span data-part="text">
                <span data-part="name">{person.name}</span>
                <span data-part="detail">{person.detail}</span>
              </span>
              {person.name === value ? (
                <span data-part="check" aria-hidden="true">
                  ✓
                </span>
              ) : null}
            </li>
          ))}
          {matches.length === 0 ? (
            <li data-part="empty" role="presentation">
              {emptyLabel}
            </li>
          ) : null}
        </ul>
      </div>
    </>
  )
}