Inputs

Shortcut Search

A search field whose keyboard hint actually works: the shortcut moves focus into the field, Escape clears it.

  • input
  • search
  • shortcut
  • keyboard

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/input-009?lang=en

Нажмите Ctrl K откуда угодно, Esc — очистить.

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 "input-009" (Shortcut Search) 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/input-009.json

Registry item: https://vibeui.ru/r/input-009.json
Installs to: components/vibeui/input-009.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 search field whose keyboard hint actually works: the shortcut moves focus into the field, Escape clears it.

A search field: the shortcut hint sits inside it and a real document handler backs it, clearing works by button and by Escape, focus returns to the field afterwards. Zero dependencies, one file.

## 3. How to use it
import { Input009 } from "@/components/vibeui/input-009"

<Input009
  placeholder="Search components"
  shortcut="K"
  onChange={(value) => setQuery(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-input-009-* palette — do not swap it for your theme tokens
- the working shortcut handler: a hint that is drawn but dead is a lie
- reading the platform through useSyncExternalStore with a server snapshot: otherwise server and client markup disagree
- removing the listener in useEffect: without it every mount adds another one
- the <kbd> tag for keys — it means "press this" and is announced correctly
- returning focus to the field after clearing: otherwise focus is stranded on a button that vanished

## 6. You may change
- the placeholder copy
- the key in the shortcut prop
- the wording of the hint under the field
- the accent through the accent prop

## 7. Rules
- The global handler captures the shortcut page-wide — do not mount two of these at once.
- Ctrl+K is taken in some browsers: check the key you pick.
- Escape clears the field first and only blurs on an empty one — those are two separate steps.
- 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/input-009.json
https://vibeui.ru/r/input-009.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-input-009-*. Клиентский: "use client". Сочетание вешается на document в useEffect и снимается при размонтировании. Модификатор (⌘ или Ctrl) читается через useSyncExternalStore: серверный снимок возвращает Ctrl, поэтому разметка сервера и первого клиентского рендера совпадает, а после гидратации на маке появляется ⌘. Значок клавиши — <kbd>, он уступает место кнопке очистки, когда в поле есть текст.

Component source

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

"use client"

import { useEffect, useId, useRef, useState, useSyncExternalStore } from "react"
import type { ComponentPropsWithoutRef, CSSProperties } from "react"

export type Input009Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "children" | "onChange"
> & {
  placeholder?: string
  shortcut?: string
  onChange?: (value: string) => void
  accent?: string
}

// Идея компонента: сочетание клавиш показано прямо в поле и оно же работает.
// Подсказка вида «⌘K», которая ничего не нажимает, — обман; здесь клавиша
// действительно уводит фокус в поле, а Escape очищает и отпускает его.
// Значок сочетания прячется, как только в поле встал курсор: он больше
// не нужен и мешает читать набранное.
const STYLES = `
:where([data-vibeui-block="input-009"]){
--vibeui-input-009-surface:oklch(1 0 0);
--vibeui-input-009-shell:oklch(0.91 0.006 265);
--vibeui-input-009-fg:oklch(0.23 0.014 265);
--vibeui-input-009-muted:oklch(0.55 0.014 265);
--vibeui-input-009-field:oklch(0.98 0.002 265);
--vibeui-input-009-border:oklch(0.89 0.008 265);
--vibeui-input-009-accent:oklch(0.55 0.17 265);
--vibeui-input-009-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="input-009"]{
display:flex;flex-direction:column;gap:0.4375rem;
width:100%;max-width:23rem;box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-input-009-surface);
border:1px solid var(--vibeui-input-009-shell);border-radius:0.875rem;
font-family:var(--vibeui-input-009-font);color:var(--vibeui-input-009-fg);
}
[data-vibeui-block="input-009"] *{box-sizing:border-box}
[data-vibeui-block="input-009"] [data-part="frame"]{
display:flex;align-items:center;gap:0.5rem;
height:2.5rem;padding:0 0.4375rem 0 0.75rem;
background:var(--vibeui-input-009-field);
border:1px solid var(--vibeui-input-009-border);border-radius:999px;
transition:border-color .16s ease,box-shadow .16s ease,background-color .16s ease;
}
[data-vibeui-block="input-009"] [data-part="frame"]:focus-within{
background:var(--vibeui-input-009-surface);
border-color:var(--vibeui-input-009-accent);
box-shadow:0 0 0 3px color-mix(in oklab,var(--vibeui-input-009-accent) 16%,transparent);
}
[data-vibeui-block="input-009"] [data-part="lens"]{flex:none;color:var(--vibeui-input-009-muted)}
[data-vibeui-block="input-009"] [data-part="lens"] svg{width:1rem;height:1rem;display:block}
[data-vibeui-block="input-009"] input{
flex:1;min-width:0;height:100%;border:0;background:none;color:inherit;
font:inherit;font-size:0.875rem;
}
[data-vibeui-block="input-009"] input:focus{outline:none}
/* Клавиша нарисована <kbd>: это ровно тот тег, который значит «нажми». */
[data-vibeui-block="input-009"] kbd{
flex:none;display:inline-flex;align-items:center;gap:0.0625rem;
height:1.375rem;padding:0 0.4375rem;border-radius:0.4375rem;
border:1px solid var(--vibeui-input-009-border);
border-bottom-width:2px;
background:var(--vibeui-input-009-surface);
font-family:inherit;font-size:0.6875rem;font-weight:600;
color:var(--vibeui-input-009-muted);
}
[data-vibeui-block="input-009"] [data-part="clear"]{
appearance:none;flex:none;cursor:pointer;
width:1.625rem;height:1.625rem;display:grid;place-items:center;
border:0;border-radius:999px;background:transparent;
color:var(--vibeui-input-009-muted);
transition:background-color .16s ease,color .16s ease;
}
[data-vibeui-block="input-009"] [data-part="clear"]:hover{
background:color-mix(in oklab,var(--vibeui-input-009-fg) 8%,transparent);
color:var(--vibeui-input-009-fg);
}
[data-vibeui-block="input-009"] [data-part="clear"]:focus-visible{
outline:2px solid var(--vibeui-input-009-accent);outline-offset:1px;
}
[data-vibeui-block="input-009"] [data-part="clear"] svg{width:0.875rem;height:0.875rem;display:block}
[data-vibeui-block="input-009"] [data-part="note"]{
margin:0;font-size:0.75rem;line-height:1.4;color:var(--vibeui-input-009-muted);
}
[data-vibeui-block="input-009"] [data-part="note"] kbd{
height:1.125rem;padding:0 0.3125rem;font-size:0.625rem;border-bottom-width:1px;
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="input-009"] *{animation:none!important;transition:none!important}}
`

// Платформа не меняется, поэтому подписка пустая: нужен только снимок.
const watchPlatform = () => () => {}
const isApple = () => /Mac|iPhone|iPad/.test(navigator.platform)
const isServer = () => false

/**
 * Поиск с рабочим сочетанием клавиш: подсказка в поле действительно нажимается.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Input009({
  placeholder = "Поиск по компонентам",
  shortcut = "K",
  onChange,
  accent,
  className,
  style,
  ...props
}: Input009Props) {
  const id = useId()
  const field = useRef<HTMLInputElement | null>(null)
  const [value, setValue] = useState("")
  // Модификатор читается через useSyncExternalStore: на сервере платформы нет,
  // и серверный снимок обязан вернуть то же, что первый клиентский рендер, —
  // иначе гидратация ломается.
  const apple = useSyncExternalStore(watchPlatform, isApple, isServer)

  useEffect(() => {
    const key = shortcut.toLowerCase()

    const onKeyDown = (event: KeyboardEvent) => {
      if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === key) {
        event.preventDefault()
        field.current?.focus()
        field.current?.select()
      }
    }

    document.addEventListener("keydown", onKeyDown)
    return () => document.removeEventListener("keydown", onKeyDown)
  }, [shortcut])

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

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

  return (
    <>
      <style href="vibeui-input-009" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="input-009"
        className={className}
        style={palette}
      >
        <div data-part="frame">
          <span data-part="lens" aria-hidden="true">
            <svg
              viewBox="0 0 16 16"
              fill="none"
              stroke="currentColor"
              strokeWidth="1.6"
            >
              <circle cx="7" cy="7" r="4.5" />
              <path d="m10.5 10.5 3 3" strokeLinecap="round" />
            </svg>
          </span>
          <input
            ref={field}
            id={id}
            type="search"
            placeholder={placeholder}
            aria-label={placeholder}
            aria-describedby={`${id}-note`}
            value={value}
            onChange={(event) => push(event.target.value)}
            onKeyDown={(event) => {
              if (event.key === "Escape") {
                event.preventDefault()
                if (value) push("")
                else field.current?.blur()
              }
            }}
          />
          {value ? (
            <button
              type="button"
              data-part="clear"
              aria-label="Очистить запрос"
              onClick={() => {
                push("")
                field.current?.focus()
              }}
            >
              <svg
                viewBox="0 0 16 16"
                fill="none"
                stroke="currentColor"
                strokeWidth="1.8"
              >
                <path d="m4 4 8 8M12 4l-8 8" strokeLinecap="round" />
              </svg>
            </button>
          ) : (
            <kbd aria-hidden="true">
              {apple ? "⌘" : "Ctrl"} {shortcut}
            </kbd>
          )}
        </div>
        <p data-part="note" id={`${id}-note`}>
          Нажмите{" "}
          <kbd>
            {apple ? "⌘" : "Ctrl"} {shortcut}
          </kbd>{" "}
          откуда угодно, <kbd>Esc</kbd> — очистить.
        </p>
      </div>
    </>
  )
}