Inputs

Icon And Clear

A group with an icon prefix on the left and a clear button on the right: the button appears with the text, and no room is reserved for it in advance.

  • inputgroup
  • clear
  • icon
  • input

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/inputgroup-007?lang=en

Кнопка очистки появляется вместе с текстом и уходит вместе с ним.

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 "inputgroup-007" (Icon And Clear) 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/inputgroup-007.json

Registry item: https://vibeui.ru/r/inputgroup-007.json
Installs to: components/vibeui/inputgroup-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 group with an icon prefix on the left and a clear button on the right: the button appears with the text, and no room is reserved for it in advance.

An icon–field–clear group: the prefix is non-interactive, the clear button appears with the text and returns focus to the field. Zero dependencies, one file.

## 3. How to use it
import { Inputgroup007 } from "@/components/vibeui/inputgroup-007"

<Inputgroup007
  label="Support passphrase"
  onChange={(value) => setWord(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-inputgroup-007-* palette — do not swap it for your theme tokens
- the collapsed borders: neighbours carry a negative margin so the halves share one line instead of two
- raising the focused element with z-index — without it the neighbour's border clips half the ring
- the icon as a non-interactive aria-hidden span: a target inside a field frame confuses
- showing the clear button only for a non-empty value: an empty field must not look like one with a disabled button
- returning focus to the field after clearing — otherwise focus is stranded on a button that vanished

## 6. You may change
- the label and placeholder copy
- the prefix icon for your scenario
- the starting field value
- the accent through the accent prop

## 7. Rules
- The button appearing and disappearing shifts the field width by a few pixels — do not animate that width.
- The button needs aria-label: it contains only an icon.
- Clearing does not submit: call your search reset from onChange if you need one.
- 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/inputgroup-007.json
https://vibeui.ru/r/inputgroup-007.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-inputgroup-007-*. Клиентский: "use client" ради состояния значения. Значок — неинтерактивный span с aria-hidden: по нему нечего нажимать. Кнопка очистки монтируется только при непустом значении и после нажатия возвращает фокус в поле. Все три части делят рамку через схлопнутые границы, фокусный элемент поднимается z-index'ом.

Component source

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

"use client"

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

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

// Идея компонента: слева значок-приставка, справа кнопка очистки, и обе
// половины сцеплены с полем одной рамкой. Значок не кнопка — по нему нечего
// нажимать, поэтому это span с aria-hidden. Кнопка очистки появляется только
// когда есть что очищать, и её место заранее не резервируется: пустое поле не
// должно выглядеть как поле с выключенной кнопкой. После очистки фокус
// возвращается в поле — иначе он повисает на исчезнувшей кнопке.
const STYLES = `
:where([data-vibeui-block="inputgroup-007"]){
--vibeui-inputgroup-007-surface:oklch(1 0 0);
--vibeui-inputgroup-007-shell:oklch(0.91 0.006 265);
--vibeui-inputgroup-007-fg:oklch(0.23 0.014 265);
--vibeui-inputgroup-007-muted:oklch(0.55 0.014 265);
--vibeui-inputgroup-007-field:oklch(0.99 0.002 265);
--vibeui-inputgroup-007-fixed:oklch(0.96 0.004 265);
--vibeui-inputgroup-007-border:oklch(0.86 0.008 265);
--vibeui-inputgroup-007-accent:oklch(0.52 0.17 320);
--vibeui-inputgroup-007-radius:0.75rem;
--vibeui-inputgroup-007-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="inputgroup-007"]{
display:flex;flex-direction:column;gap:0.4375rem;
width:100%;max-width:22rem;box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-inputgroup-007-surface);
border:1px solid var(--vibeui-inputgroup-007-shell);border-radius:0.875rem;
font-family:var(--vibeui-inputgroup-007-font);color:var(--vibeui-inputgroup-007-fg);
}
[data-vibeui-block="inputgroup-007"] *{box-sizing:border-box}
[data-vibeui-block="inputgroup-007"] label{font-size:0.8125rem;font-weight:600}
[data-vibeui-block="inputgroup-007"] [data-part="group"]{display:flex;align-items:stretch}
[data-vibeui-block="inputgroup-007"] [data-part="group"] > *{
position:relative;height:2.625rem;
border:1px solid var(--vibeui-inputgroup-007-border);
border-radius:0;margin-left:-1px;font:inherit;color:inherit;
}
[data-vibeui-block="inputgroup-007"] [data-part="group"] > *:first-child{
margin-left:0;
border-radius:var(--vibeui-inputgroup-007-radius) 0 0 var(--vibeui-inputgroup-007-radius);
}
[data-vibeui-block="inputgroup-007"] [data-part="group"] > *:last-child{
border-radius:0 var(--vibeui-inputgroup-007-radius) var(--vibeui-inputgroup-007-radius) 0;
}
[data-vibeui-block="inputgroup-007"] [data-part="group"] > *:focus,
[data-vibeui-block="inputgroup-007"] [data-part="group"] > *:focus-visible{
z-index:1;outline:2px solid var(--vibeui-inputgroup-007-accent);outline-offset:-1px;
border-color:var(--vibeui-inputgroup-007-accent);
}
/* Приставка со значком — не мишень: ни курсора, ни фокуса. */
[data-vibeui-block="inputgroup-007"] [data-part="icon"]{
flex:none;display:grid;place-items:center;width:2.5rem;
background:var(--vibeui-inputgroup-007-fixed);
color:var(--vibeui-inputgroup-007-muted);
}
[data-vibeui-block="inputgroup-007"] [data-part="icon"] svg{width:1rem;height:1rem;display:block}
[data-vibeui-block="inputgroup-007"] input{
flex:1;min-width:0;padding:0 0.75rem;font-size:0.875rem;
background:var(--vibeui-inputgroup-007-field);
}
[data-vibeui-block="inputgroup-007"] [data-part="clear"]{
appearance:none;flex:none;cursor:pointer;width:2.5rem;
display:grid;place-items:center;
background:var(--vibeui-inputgroup-007-fixed);
color:var(--vibeui-inputgroup-007-muted);
transition:background-color .16s ease,color .16s ease;
}
[data-vibeui-block="inputgroup-007"] [data-part="clear"]:hover{
background:color-mix(in oklab,var(--vibeui-inputgroup-007-accent) 14%,var(--vibeui-inputgroup-007-fixed));
color:var(--vibeui-inputgroup-007-fg);
}
[data-vibeui-block="inputgroup-007"] [data-part="clear"] svg{width:0.875rem;height:0.875rem;display:block}
[data-vibeui-block="inputgroup-007"] [data-part="hint"]{
margin:0;font-size:0.75rem;line-height:1.4;color:var(--vibeui-inputgroup-007-muted);
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="inputgroup-007"] *{animation:none!important;transition:none!important}}
`

/**
 * Сцепка со значком слева и кнопкой очистки справа: кнопка есть, только если есть что стирать.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Inputgroup007({
  label = "Кодовое слово поддержки",
  placeholder = "Слово из письма",
  onChange,
  accent,
  className,
  style,
  ...props
}: Inputgroup007Props) {
  const id = useId()
  const field = useRef<HTMLInputElement | null>(null)
  const [value, setValue] = useState("вьюга-77")

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

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

  return (
    <>
      <style href="vibeui-inputgroup-007" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="inputgroup-007"
        className={className}
        style={palette}
      >
        <label htmlFor={id}>{label}</label>
        <div data-part="group">
          <span data-part="icon" aria-hidden="true">
            <svg
              viewBox="0 0 16 16"
              fill="none"
              stroke="currentColor"
              strokeWidth="1.5"
            >
              <rect x="2.5" y="7" width="11" height="7" rx="1.75" />
              <path d="M5 7V5a3 3 0 0 1 6 0v2" strokeLinecap="round" />
            </svg>
          </span>
          <input
            ref={field}
            id={id}
            type="text"
            autoComplete="off"
            placeholder={placeholder}
            value={value}
            aria-describedby={`${id}-hint`}
            onChange={(event) => push(event.target.value)}
          />
          {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"
                aria-hidden="true"
              >
                <path d="m4 4 8 8M12 4l-8 8" strokeLinecap="round" />
              </svg>
            </button>
          ) : null}
        </div>
        <p data-part="hint" id={`${id}-hint`}>
          Кнопка очистки появляется вместе с текстом и уходит вместе с ним.
        </p>
      </div>
    </>
  )
}