Checkbox

Group Error

The error belongs to the group, not to a row: "pick at least one" is shown by a border, a sign and a line saying what to do.

  • checkbox
  • validation
  • error
  • fieldset

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/checkbox-015?lang=en

What does your team do
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 "checkbox-015" (Group Error) 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/checkbox-015.json

Registry item: https://vibeui.ru/r/checkbox-015.json
Installs to: components/vibeui/checkbox-015.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
The error belongs to the group, not to a row: "pick at least one" is shown by a border, a sign and a line saying what to do.

A checkbox group validated as a whole: the "at least one" error applies to the set, shown by the group's border, an exclamation sign and a hint about what to do next. Zero dependencies, one file.

## 3. How to use it
import { Checkbox015 } from "@/components/vibeui/checkbox-015"

<Checkbox015
  legend="What does your team do"
  options={options}
  onSubmitValue={save}
/>

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-checkbox-015-* palette — do not swap it for your theme tokens
- the error on the fieldset: "at least one" is a property of the set, not of a single row
- the "!" sign next to the text — red alone cannot carry an error
- aria-invalid and aria-describedby on the group: the link to the message must exist in markup
- role="alert" on the message so it is heard right after submission
- the second line with the hint: an error without "what to do" solves nothing

## 6. You may change
- the options array — the choices in the group
- legend — the group's name
- error and hint — the error and helper copy
- the onSubmitValue handler and the accent through the accent prop

## 7. Rules
- The error clears on the first tick — holding it until the next submit is cruel.
- The component submits nothing: onSubmitValue fires only with a non-empty selection.
- Document consent is a different case: the error sits on one box there, use checkbox-005.
- 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/checkbox-015.json
https://vibeui.ru/r/checkbox-015.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-checkbox-015-*. Клиентский: "use client". Ошибка живёт на fieldset: он получает data-invalid, aria-invalid и aria-describedby с идентификатором из useId. Сообщение объявлено role="alert" и состоит из знака «!» кружком и двух строк — что не так и что сделать. Состояние ошибки пересчитывается при отправке и снимается сразу после первой отметки.

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 Checkbox015Props = Omit<
  ComponentPropsWithoutRef<"form">,
  "children" | "onChange" | "onSubmit"
> & {
  legend?: string
  options?: string[]
  error?: string
  hint?: string
  onSubmitValue?: (value: string[]) => void
  accent?: string
}

// Идея компонента: ошибка не у отдельной галочки, а у всей группы —
// «отметьте хотя бы одно» относится к набору, а не к строке. Ошибочное
// состояние читается тремя способами сразу: рамка группы, знак «!» и текст
// с объяснением, что именно сделать. Одного цвета мало.
const STYLES = `
:where([data-vibeui-block="checkbox-015"]){
--vibeui-checkbox-015-bg:oklch(1 0 0);
--vibeui-checkbox-015-fg:oklch(0.22 0.014 265);
--vibeui-checkbox-015-muted:oklch(0.55 0.014 265);
--vibeui-checkbox-015-border:oklch(0.9 0.006 265);
--vibeui-checkbox-015-accent:oklch(0.53 0.16 265);
--vibeui-checkbox-015-danger:oklch(0.55 0.2 25);
--vibeui-checkbox-015-danger-soft:oklch(0.96 0.03 25);
--vibeui-checkbox-015-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="checkbox-015"]{
display:block;width:100%;max-width:21rem;box-sizing:border-box;
padding:0.9375rem;border:1px solid var(--vibeui-checkbox-015-border);border-radius:0.9375rem;
background:var(--vibeui-checkbox-015-bg);
font-family:var(--vibeui-checkbox-015-font);color:var(--vibeui-checkbox-015-fg);
}
[data-vibeui-block="checkbox-015"] fieldset{
display:flex;flex-direction:column;gap:0.125rem;
margin:0;padding:0.625rem;border:1.5px solid var(--vibeui-checkbox-015-border);border-radius:0.75rem;
transition:border-color .15s ease,background-color .15s ease;
}
/* Ошибка на группе, а не на строке: требование «хотя бы одно» относится
   ко всему набору. */
[data-vibeui-block="checkbox-015"] fieldset[data-invalid="true"]{
border-color:var(--vibeui-checkbox-015-danger);
background:var(--vibeui-checkbox-015-danger-soft);
}
[data-vibeui-block="checkbox-015"] legend{
float:left;width:100%;padding:0 0 0.375rem;font-size:0.875rem;font-weight:650;
}
[data-vibeui-block="checkbox-015"] label{
clear:both;display:flex;align-items:center;gap:0.625rem;
min-height:2rem;font-size:0.875rem;cursor:pointer;
}
[data-vibeui-block="checkbox-015"] input{
appearance:none;position:relative;flex:none;cursor:pointer;
width:1.0625rem;height:1.0625rem;margin:0;box-sizing:border-box;
border:1.5px solid var(--vibeui-checkbox-015-border);border-radius:0.3125rem;
background:var(--vibeui-checkbox-015-bg);
transition:background-color .15s ease,border-color .15s ease;
}
[data-vibeui-block="checkbox-015"] fieldset[data-invalid="true"] input{border-color:var(--vibeui-checkbox-015-danger)}
[data-vibeui-block="checkbox-015"] input:checked{border-color:transparent;background:var(--vibeui-checkbox-015-accent)}
[data-vibeui-block="checkbox-015"] input:checked::after{
content:"";position:absolute;left:50%;top:50%;
width:0.25rem;height:0.4375rem;margin:-0.3125rem 0 0 -0.125rem;
border-right:2px solid oklch(0.99 0.01 265);border-bottom:2px solid oklch(0.99 0.01 265);
transform:rotate(45deg);
}
[data-vibeui-block="checkbox-015"] input:focus-visible{outline:2px solid var(--vibeui-checkbox-015-accent);outline-offset:2px}
[data-vibeui-block="checkbox-015"] [data-part="error"]{
display:flex;align-items:flex-start;gap:0.5rem;
margin:0.625rem 0 0;font-size:0.8125rem;line-height:1.4;color:var(--vibeui-checkbox-015-danger);
}
/* Знак «!» кружком: ошибка обязана читаться и в чёрно-белой печати,
   и при дальтонизме. */
[data-vibeui-block="checkbox-015"] [data-part="sign"]{
display:flex;align-items:center;justify-content:center;flex:none;
width:1.125rem;height:1.125rem;margin-top:0.0625rem;border-radius:9999px;
background:var(--vibeui-checkbox-015-danger);color:oklch(0.99 0.01 25);
font-size:0.75rem;font-weight:800;line-height:1;
}
[data-vibeui-block="checkbox-015"] [data-part="fix"]{
display:block;margin-top:0.125rem;color:var(--vibeui-checkbox-015-muted);font-size:0.75rem;
}
[data-vibeui-block="checkbox-015"] button{
appearance:none;border:0;cursor:pointer;margin-top:0.75rem;
height:2.25rem;padding:0 0.875rem;border-radius:0.625rem;
font:inherit;font-size:0.8125rem;font-weight:650;
background:var(--vibeui-checkbox-015-accent);color:oklch(0.99 0.01 265);
}
[data-vibeui-block="checkbox-015"] button:focus-visible{outline:2px solid var(--vibeui-checkbox-015-accent);outline-offset:2px}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="checkbox-015"] *{animation:none!important;transition:none!important}}
`

const DEFAULT_OPTIONS = [
  "Разработка",
  "Дизайн",
  "Аналитика",
  "Поддержка клиентов",
]

/**
 * Группа чекбоксов с ошибкой на уровне набора: рамка, знак и объяснение,
 * что сделать. Один файл, ноль зависимостей, собственная палитра.
 */
export function Checkbox015({
  legend = "Чем занимается ваша команда",
  options = DEFAULT_OPTIONS,
  error = "Отметьте хотя бы одно направление",
  hint = "Мы подберём шаблоны под выбранные направления.",
  onSubmitValue,
  accent,
  className,
  style,
  ...props
}: Checkbox015Props) {
  const [value, setValue] = useState<string[]>([])
  const [checked, setChecked] = useState(true)
  const errorId = useId()

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

  const invalid = checked && value.length === 0

  const toggle = (option: string) => {
    setValue(
      value.includes(option)
        ? value.filter((item) => item !== option)
        : [...value, option],
    )
  }

  return (
    <>
      <style href="vibeui-checkbox-015" precedence="medium">
        {STYLES}
      </style>
      <form
        {...props}
        data-vibeui-block="checkbox-015"
        className={className}
        style={palette}
        onSubmit={(event) => {
          event.preventDefault()
          setChecked(true)

          if (value.length > 0) {
            onSubmitValue?.(value)
          }
        }}
      >
        <fieldset
          data-invalid={invalid}
          aria-invalid={invalid || undefined}
          aria-describedby={invalid ? errorId : undefined}
        >
          <legend>{legend}</legend>
          {options.map((option) => (
            <label key={option}>
              <input
                type="checkbox"
                checked={value.includes(option)}
                onChange={() => toggle(option)}
              />
              <span>{option}</span>
            </label>
          ))}
        </fieldset>
        {invalid ? (
          <p data-part="error" id={errorId} role="alert">
            <span data-part="sign" aria-hidden="true">
              !
            </span>
            <span>
              {error}
              <span data-part="fix">{hint}</span>
            </span>
          </p>
        ) : null}
        <button type="submit">Продолжить</button>
      </form>
    </>
  )
}