Inputs

Invalid Select

A select with a validation error that clears itself on the first meaningful choice: red border, tint, sign and text.

  • select
  • validation
  • error
  • 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/select-008?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 "select-008" (Invalid Select) 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/select-008.json

Registry item: https://vibeui.ru/r/select-008.json
Installs to: components/vibeui/select-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
A select with a validation error that clears itself on the first meaningful choice: red border, tint, sign and text.

A select with a validation error that disappears on the first valid choice. One file, zero dependencies, a client component.

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

<Select008
  label="Legal form"
  error="We cannot issue an invoice without this"
/>

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-select-008-* palette — do not swap it for your theme tokens
- the error carried by more than colour: border, tint, sign and text — colour alone fails for colour-blind users
- aria-invalid on the field and role="alert" on the message: without them the error never reaches a screen reader
- clearing the error on the first valid choice — an error that lingers after a fix reads as an accusation
- aria-describedby pointing at the same id in both states: the link must not break
- the component's own light surface — without it the dark text disappears on a dark page

## 6. You may change
- the field caption through label
- the message text through error
- the first row of the list through placeholder
- the set of options through options

## 7. Rules
- The check here is illustrative: real validation lives in the form and on the server.
- The error is shown immediately for the showcase — in a live form you switch it on after the first submit.
- Error text should say what to do, not what happened: "pick a legal form" beats "field is empty".
- 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/select-008.json
https://vibeui.ru/r/select-008.json

Клиентский компонент: useState хранит значение, ошибка выводится, пока оно пустое. Состояние вынесено в data-invalid на корне, поэтому CSS красит рамку, заливку и стрелку одним переключателем. Сообщение объявлено role="alert" и связано с полем через aria-describedby; поле помечено aria-invalid. Значок ошибки нарисован рамкой круга и двумя псевдоэлементами, без иконочного пакета. Палитра в --vibeui-select-008-*.

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 } from "react"

export type Select008Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "children" | "onChange"
> & {
  label?: string
  options?: string[]
  placeholder?: string
  error?: string
  accent?: string
}

// Идея компонента: ошибка валидации, которая уходит сама. Красная рамка,
// висящая до повторной отправки формы, выглядит как обвинение: человек уже
// исправил поле, а его всё ещё ругают. Здесь сообщение снимается на первом
// же осмысленном выборе, а до этого связано с полем через aria-describedby.
const STYLES = `
:where([data-vibeui-block="select-008"]){
--vibeui-select-008-surface:oklch(1 0 0);
--vibeui-select-008-surface-border:oklch(0.91 0.006 265);
--vibeui-select-008-fg:oklch(0.23 0.016 265);
--vibeui-select-008-muted:oklch(0.55 0.014 265);
--vibeui-select-008-field:oklch(0.985 0.002 265);
--vibeui-select-008-border:oklch(0.87 0.008 265);
--vibeui-select-008-accent:oklch(0.55 0.19 262);
--vibeui-select-008-danger:oklch(0.55 0.2 25);
--vibeui-select-008-danger-tint:oklch(0.55 0.2 25 / 9%);
--vibeui-select-008-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="select-008"]{
display:flex;flex-direction:column;gap:0.375rem;
width:100%;max-width:20rem;box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-select-008-surface);
border:1px solid var(--vibeui-select-008-surface-border);border-radius:0.875rem;
font-family:var(--vibeui-select-008-font);color:var(--vibeui-select-008-fg);
}
[data-vibeui-block="select-008"] [data-part="label"]{font-size:0.8125rem;font-weight:600}
[data-vibeui-block="select-008"] [data-part="field"]{position:relative;display:block}
[data-vibeui-block="select-008"] select{
appearance:none;-webkit-appearance:none;
width:100%;box-sizing:border-box;margin:0;height:2.75rem;
padding:0 2.5rem 0 0.875rem;
border:1px solid var(--vibeui-select-008-border);border-radius:0.625rem;
background:var(--vibeui-select-008-field);color:inherit;
font:inherit;font-size:0.9375rem;cursor:pointer;
transition:border-color .16s ease,box-shadow .16s ease;
}
[data-vibeui-block="select-008"] select:focus{
outline:none;border-color:var(--vibeui-select-008-accent);
box-shadow:0 0 0 3px color-mix(in oklab,var(--vibeui-select-008-accent) 22%,transparent);
}
/* Ошибка — это рамка, заливка и текст сразу: одного цвета рамки не хватает
   тем, кто его не различает. */
[data-vibeui-block="select-008"][data-invalid="true"] select{
border-color:var(--vibeui-select-008-danger);
background:var(--vibeui-select-008-danger-tint);
}
[data-vibeui-block="select-008"][data-invalid="true"] select:focus{
box-shadow:0 0 0 3px color-mix(in oklab,var(--vibeui-select-008-danger) 22%,transparent);
}
[data-vibeui-block="select-008"] [data-part="arrow"]{
position:absolute;right:1rem;top:50%;
width:0.4375rem;height:0.4375rem;margin-top:-0.3125rem;pointer-events:none;
border-right:1.5px solid var(--vibeui-select-008-muted);
border-bottom:1.5px solid var(--vibeui-select-008-muted);
transform:rotate(45deg);
}
[data-vibeui-block="select-008"][data-invalid="true"] [data-part="arrow"]{
border-right-color:var(--vibeui-select-008-danger);
border-bottom-color:var(--vibeui-select-008-danger);
}
[data-vibeui-block="select-008"] [data-part="error"]{
display:flex;align-items:flex-start;gap:0.375rem;margin:0;
font-size:0.75rem;line-height:1.4;color:var(--vibeui-select-008-danger);
}
/* Кружок с восклицательным знаком нарисован рамкой и псевдоэлементом:
   значок ошибки без иконочного пакета. */
[data-vibeui-block="select-008"] [data-part="sign"]{
position:relative;flex:none;width:0.875rem;height:0.875rem;margin-top:0.0625rem;
border:1.5px solid currentColor;border-radius:9999px;
}
[data-vibeui-block="select-008"] [data-part="sign"]::before{
content:"";position:absolute;left:50%;top:0.125rem;
width:1.5px;height:0.3125rem;margin-left:-0.75px;background:currentColor;
}
[data-vibeui-block="select-008"] [data-part="sign"]::after{
content:"";position:absolute;left:50%;bottom:0.125rem;
width:1.5px;height:1.5px;margin-left:-0.75px;background:currentColor;
}
[data-vibeui-block="select-008"] [data-part="ok"]{
margin:0;font-size:0.75rem;line-height:1.4;color:var(--vibeui-select-008-muted);
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="select-008"] *{animation:none!important;transition:none!important}}
`

const DEFAULT_OPTIONS = [
  "Индивидуальный предприниматель",
  "Общество с ограниченной ответственностью",
  "Самозанятый",
  "Физическое лицо",
]

/**
 * Select с ошибкой валидации, которая снимается при первом верном выборе.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Select008({
  label = "Форма собственности",
  options = DEFAULT_OPTIONS,
  placeholder = "Не выбрано",
  error = "Без этого поля счёт не выставить",
  accent,
  className,
  style,
  ...props
}: Select008Props) {
  const id = useId()
  const [value, setValue] = useState("")
  const invalid = value === ""

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

  return (
    <>
      <style href="vibeui-select-008" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="select-008"
        data-invalid={invalid}
        className={className}
        style={palette}
      >
        <label data-part="label" htmlFor={id}>
          {label}
        </label>
        <span data-part="field">
          <select
            id={id}
            value={value}
            aria-invalid={invalid}
            aria-describedby={`${id}-message`}
            onChange={(event) => setValue(event.target.value)}
          >
            <option value="" disabled>
              {placeholder}
            </option>
            {options.map((option) => (
              <option key={option} value={option}>
                {option}
              </option>
            ))}
          </select>
          <span data-part="arrow" aria-hidden="true" />
        </span>
        {invalid ? (
          <p data-part="error" id={`${id}-message`} role="alert">
            <span data-part="sign" aria-hidden="true" />
            <span>{error}</span>
          </p>
        ) : (
          <p data-part="ok" id={`${id}-message`}>
            Реквизиты подставим автоматически.
          </p>
        )}
      </div>
    </>
  )
}