Autocomplete

Email Domain

Email completes inside the field itself: the grey domain tail behind the caret is accepted with Tab.

  • autocomplete
  • email
  • inline
  • 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-008?lang=en

Tab допишет домен yandex.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 "autocomplete-008" (Email Domain) 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-008.json

Registry item: https://vibeui.ru/r/autocomplete-008.json
Installs to: components/vibeui/autocomplete-008.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
Email completes inside the field itself: the grey domain tail behind the caret is accepted with Tab.

An email field that completes the domain: after the @ a grey tail appears behind the caret and Tab accepts it. There is no dropdown at all. Zero dependencies, one file, its own palette.

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

<Autocomplete008
  domains={["gmail.com", "outlook.com"]}
  onChange={(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-autocomplete-008-* palette — do not swap it for your theme tokens
- the shared rule for the ghost layer and the input: any font or padding drift moves the tail
- aria-hidden on the ghost layer: a screen reader would otherwise read the address twice
- the suggestion appearing only after the @ — before it there is nothing to guess
- accepting the tail with Tab and with ArrowRight at the end of the line
- the email input type and inputMode: it is a different keyboard on a phone

## 6. You may change
- the domains list for your audience
- the label, placeholder and hint copy
- the onChange handler
- the accent through the accent prop

## 7. Rules
- Domain order matters: the first one is offered right after the @, so put the most common there.
- The component validates nothing: validation belongs to the form, not the hint.
- The ghost layer does not wrap: a very long address is clipped at the field edge, exactly as in the input.
- 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-008.json
https://vibeui.ru/r/autocomplete-008.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-autocomplete-008-*. Клиентский: "use client". Хвост рисует слой под полем: набранное в нём прозрачно (тег i), видна только подсказка. Слой и поле объявлены одним правилом, чтобы шрифт, отступы и высота строки совпадали до пикселя. Tab и стрелка вправо в конце строки принимают дописанное; слой помечен aria-hidden.

Component source

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

"use client"

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

export type Autocomplete008Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "children" | "onChange" | "defaultValue"
> & {
  label?: string
  placeholder?: string
  domains?: string[]
  defaultValue?: string
  onChange?: (value: string) => void
  accent?: string
}

// Идея компонента: почта дописывается прямо в поле. Хвост домена показан
// серым за курсором и принимается Tab — список из пяти строк ради «gmail.com»
// избыточен, а опечатка в домене стоит письма. Подсказка появляется только
// после «@»: до собаки угадывать нечего.
const STYLES = `
:where([data-vibeui-block="autocomplete-008"]){
--vibeui-autocomplete-008-bg:oklch(1 0 0);
--vibeui-autocomplete-008-fg:oklch(0.22 0.014 265);
--vibeui-autocomplete-008-muted:oklch(0.52 0.014 265);
--vibeui-autocomplete-008-ghost:oklch(0.72 0.012 265);
--vibeui-autocomplete-008-border:oklch(0.9 0.006 265);
--vibeui-autocomplete-008-field:oklch(0.985 0.002 265);
--vibeui-autocomplete-008-accent:oklch(0.55 0.17 265);
--vibeui-autocomplete-008-radius:0.625rem;
--vibeui-autocomplete-008-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="autocomplete-008"]{
display:flex;flex-direction:column;gap:0.375rem;
width:100%;max-width:22rem;box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-autocomplete-008-bg);
border:1px solid var(--vibeui-autocomplete-008-border);
border-radius:calc(var(--vibeui-autocomplete-008-radius) + 0.25rem);
color:var(--vibeui-autocomplete-008-fg);
font-family:var(--vibeui-autocomplete-008-font);
}
[data-vibeui-block="autocomplete-008"] label{font-size:0.8125rem;font-weight:600}
/* Подложка и рамка живут на обёртке, а поле прозрачно: непрозрачный инпут
   закрыл бы собой слой с хвостом. */
[data-vibeui-block="autocomplete-008"] [data-part="field"]{
position:relative;display:block;
border:1px solid var(--vibeui-autocomplete-008-border);
border-radius:var(--vibeui-autocomplete-008-radius);
background:var(--vibeui-autocomplete-008-field);
}
[data-vibeui-block="autocomplete-008"] [data-part="field"]:focus-within{
outline:2px solid var(--vibeui-autocomplete-008-accent);outline-offset:1px;border-color:transparent;
}
/* Тень и поле обязаны совпасть по шрифту и отступам до пикселя: любое
   расхождение — и хвост уезжает относительно набранного. */
[data-vibeui-block="autocomplete-008"] [data-part="ghost"],
[data-vibeui-block="autocomplete-008"] input{
box-sizing:border-box;width:100%;height:2.5rem;padding:0 0.75rem;
border:1px solid transparent;border-radius:var(--vibeui-autocomplete-008-radius);
font-family:inherit;font-size:0.875rem;line-height:2.375rem;
letter-spacing:normal;white-space:pre;
}
[data-vibeui-block="autocomplete-008"] [data-part="ghost"]{
position:absolute;inset:0;pointer-events:none;overflow:hidden;
color:var(--vibeui-autocomplete-008-ghost);
}
[data-vibeui-block="autocomplete-008"] [data-part="ghost"] i{color:transparent;font-style:normal}
[data-vibeui-block="autocomplete-008"] input{
position:relative;background:transparent;color:inherit;
}
[data-vibeui-block="autocomplete-008"] input::placeholder{color:var(--vibeui-autocomplete-008-muted)}
[data-vibeui-block="autocomplete-008"] input:focus{outline:none}
[data-vibeui-block="autocomplete-008"] [data-part="hint"]{
display:flex;align-items:center;gap:0.375rem;font-size:0.75rem;color:var(--vibeui-autocomplete-008-muted);
}
[data-vibeui-block="autocomplete-008"] kbd{
padding:0.0625rem 0.3125rem;border-radius:0.25rem;
border:1px solid var(--vibeui-autocomplete-008-border);
font-family:inherit;font-size:0.6875rem;
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="autocomplete-008"] *{animation:none!important;transition:none!important}}
`

const DEFAULT_DOMAINS = [
  "gmail.com",
  "yandex.ru",
  "mail.ru",
  "outlook.com",
  "icloud.com",
  "proton.me",
]

function completion(value: string, domains: string[]) {
  const at = value.indexOf("@")
  if (at < 0) return ""
  const typed = value.slice(at + 1)
  if (!typed) return domains[0].slice(typed.length)
  const found = domains.find(
    (domain) => domain.startsWith(typed) && domain !== typed,
  )
  return found ? found.slice(typed.length) : ""
}

/**
 * Почта с дописыванием домена: серый хвост принимается Tab.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Autocomplete008({
  label = "Почта",
  placeholder = "имя@почта",
  domains = DEFAULT_DOMAINS,
  defaultValue = "anna.petrova@ya",
  onChange,
  accent,
  className,
  style,
  ...props
}: Autocomplete008Props) {
  const id = useId()
  const [value, setValue] = useState(defaultValue)
  const rest = completion(value, domains)

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

  const update = (next: string) => {
    setValue(next)
    onChange?.(next)
  }

  const onKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
    if (!rest) return
    const atEnd =
      event.currentTarget.selectionStart === value.length &&
      event.currentTarget.selectionEnd === value.length
    if (event.key === "Tab" || (event.key === "ArrowRight" && atEnd)) {
      event.preventDefault()
      update(value + rest)
    }
  }

  return (
    <>
      <style href="vibeui-autocomplete-008" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="autocomplete-008"
        className={className}
        style={palette}
      >
        <label htmlFor={id}>{label}</label>
        <span data-part="field">
          <span data-part="ghost" aria-hidden="true">
            <i>{value}</i>
            {rest}
          </span>
          <input
            id={id}
            type="email"
            inputMode="email"
            autoComplete="off"
            spellCheck={false}
            placeholder={placeholder}
            value={value}
            aria-describedby={`${id}-hint`}
            onChange={(event) => update(event.target.value)}
            onKeyDown={onKeyDown}
          />
        </span>
        <span data-part="hint" id={`${id}-hint`}>
          {rest ? (
            <>
              <kbd>Tab</kbd> допишет домен {value.slice(value.indexOf("@") + 1)}
              {rest}
            </>
          ) : (
            "После @ поле допишет домен"
          )}
        </span>
      </div>
    </>
  )
}