Accordion

Native Accordion

An accordion built on native details and summary: it opens without a line of JS, and the name attribute keeps only one section open.

  • accordion
  • faq
  • details
  • no-js

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/accordion-001?lang=en

Что именно я получаю после установки?

Один файл компонента в вашем проекте. Тот же самый, который вы видели в превью: ни сборки, ни обёрток, ни привязки к нашей теме.

А если у меня своя дизайн-система?

Компонент несёт собственную палитру в локальных переменных. Переопределите их — и он встанет в вашу тему, не трогая остальной проект.

Нужно ли ставить дополнительные библиотеки?

Нет. Зависимости объявлены в метаданных каждого компонента, и у большинства их ноль: только React.

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 "accordion-001" (Native Accordion) 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/accordion-001.json

Registry item: https://vibeui.ru/r/accordion-001.json
Installs to: components/vibeui/accordion-001.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
An accordion built on native details and summary: it opens without a line of JS, and the name attribute keeps only one section open.

A JS-free accordion: native details and summary handle opening, and the name attribute on details makes the sections exclusive. Keyboard support, find-on-page (the browser opens the matching section) and pre-hydration behaviour all come for free. The chevron and layout are CSS, and spacing is measured against the component's own width. Zero dependencies, one file, its own palette.

## 3. How to use it
import { Accordion001 } from "@/components/vibeui/accordion-001"

<Accordion001
  items={[
    { question: "What do I get after installing?", answer: "One component file in your project." },
  ]}
/>

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-accordion-001-* palette — do not swap it for your theme tokens (bg-card, border-border and the like)
- the native details/summary: replacing them with buttons and useState gives up find-on-page, keyboard behaviour and pre-hydration state
- the name attribute on details — that is the exclusivity, no separate state is needed for it
- hiding the system marker (list-style:none and ::-webkit-details-marker) alongside the custom chevron
- the focus-visible outline on summary with its negative offset: headings are tabbed through
- the chevron rotation tied to details[open] and the prefers-reduced-motion rule
- the @container query instead of a media query: the accordion lives both in a narrow column and full width
- the <style> block inside the component — it holds the palette, the layout and the chevron

## 6. You may change
- the items array: questions and answers
- exclusive — whether only one section stays open
- defaultOpen — which section starts open; -1 closes them all
- the accent through the accent prop — it colours hover, focus and the chevron
- max width and outer spacing through className

## 7. Rules
- Do not put a link to another section of the same accordion in an answer: with exclusive on, it closes the current one.
- The name attribute on details is supported by current browsers; older ones simply leave the sections independent, which does not break the component.
- Do not animate the open height by hand: native details has no such animation, and faking it brings back the JS this component exists to avoid.
- 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/accordion-001.json
https://vibeui.ru/r/accordion-001.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-accordion-001-*. Раскрытие держат нативные <details>/<summary>, поэтому состояние работает до гидратации и не требует React. Взаимное исключение включается атрибутом name у details: у разделов с одним именем открытым остаётся только один. Значок — две грани квадрата, поворот привязан к details[open]. Внутренние отступы и кегль считаются от собственной ширины через @container.

Component source

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

import type { ComponentPropsWithoutRef, CSSProperties } from "react"

export type Accordion001Item = {
  question: string
  answer: string
}

export type Accordion001Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "children"
> & {
  items?: Accordion001Item[]
  /** Открытым остаётся только один раздел: группировка через атрибут name. */
  exclusive?: boolean
  /** Номер раздела, открытого сразу. -1 — все закрыты. */
  defaultOpen?: number
  accent?: string
}

// Идея компонента: аккордеон без единой строки JS. Раскрытие держат нативные
// details/summary, взаимное исключение — атрибут name на details. Отсюда
// бесплатные клавиатура, поиск по странице и работа до гидратации.
const STYLES = `
:where([data-vibeui-block="accordion-001"]){
--vibeui-accordion-001-fg:oklch(0.24 0.016 265);
--vibeui-accordion-001-muted:oklch(0.5 0.014 265);
--vibeui-accordion-001-bg:oklch(1 0 0);
--vibeui-accordion-001-border:oklch(0.9 0.006 265);
--vibeui-accordion-001-accent:oklch(0.55 0.2 262);
--vibeui-accordion-001-radius:0.75rem;
--vibeui-accordion-001-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
container-type:inline-size;
}
[data-vibeui-block="accordion-001"]{
display:flex;flex-direction:column;width:100%;max-width:44rem;box-sizing:border-box;
border:1px solid var(--vibeui-accordion-001-border);
border-radius:var(--vibeui-accordion-001-radius);
background:var(--vibeui-accordion-001-bg);color:var(--vibeui-accordion-001-fg);
font-family:var(--vibeui-accordion-001-font);overflow:hidden;
}
[data-vibeui-block="accordion-001"] details + details{border-top:1px solid var(--vibeui-accordion-001-border)}
[data-vibeui-block="accordion-001"] summary{
display:flex;align-items:center;justify-content:space-between;gap:1rem;
padding:0.9375rem 1.125rem;cursor:pointer;list-style:none;
font-size:0.9375rem;font-weight:500;line-height:1.4;
transition:color .16s ease;
}
[data-vibeui-block="accordion-001"] summary::-webkit-details-marker{display:none}
[data-vibeui-block="accordion-001"] summary:hover{color:var(--vibeui-accordion-001-accent)}
[data-vibeui-block="accordion-001"] summary:focus-visible{
outline:2px solid var(--vibeui-accordion-001-accent);outline-offset:-2px;
}
/* Значок — две грани квадрата; поворачивается вместе с открытием раздела. */
[data-vibeui-block="accordion-001"] [data-part="chevron"]{
width:0.4375rem;height:0.4375rem;flex:none;margin-right:0.25rem;
border-right:1.5px solid var(--vibeui-accordion-001-muted);
border-bottom:1.5px solid var(--vibeui-accordion-001-muted);
transform:rotate(45deg) translate(-0.125rem,-0.125rem);
transition:transform .18s ease,border-color .16s ease;
}
[data-vibeui-block="accordion-001"] details[open] [data-part="chevron"]{
transform:rotate(225deg) translate(-0.125rem,-0.125rem);
border-right-color:var(--vibeui-accordion-001-accent);
border-bottom-color:var(--vibeui-accordion-001-accent);
}
[data-vibeui-block="accordion-001"] [data-part="answer"]{
margin:0;padding:0 1.125rem 1.0625rem;
font-size:0.875rem;line-height:1.6;color:var(--vibeui-accordion-001-muted);
}
@container (min-width: 32rem){
[data-vibeui-block="accordion-001"] summary{padding:1.0625rem 1.375rem;font-size:1rem}
[data-vibeui-block="accordion-001"] [data-part="answer"]{padding:0 1.375rem 1.25rem;font-size:0.9375rem}
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="accordion-001"] *{animation:none!important;transition:none!important}}
`

const DEFAULT_ITEMS: Accordion001Item[] = [
  {
    question: "Что именно я получаю после установки?",
    answer:
      "Один файл компонента в вашем проекте. Тот же самый, который вы видели в превью: ни сборки, ни обёрток, ни привязки к нашей теме.",
  },
  {
    question: "А если у меня своя дизайн-система?",
    answer:
      "Компонент несёт собственную палитру в локальных переменных. Переопределите их — и он встанет в вашу тему, не трогая остальной проект.",
  },
  {
    question: "Нужно ли ставить дополнительные библиотеки?",
    answer:
      "Нет. Зависимости объявлены в метаданных каждого компонента, и у большинства их ноль: только React.",
  },
]

/**
 * Аккордеон на нативных details/summary: раскрытие без JS.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Accordion001({
  items = DEFAULT_ITEMS,
  exclusive = true,
  defaultOpen = 0,
  accent,
  className,
  style,
  ...props
}: Accordion001Props) {
  const palette = {
    ...(accent ? { "--vibeui-accordion-001-accent": accent } : null),
    ...style,
  } as CSSProperties

  return (
    <>
      <style href="vibeui-accordion-001" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="accordion-001"
        className={className}
        style={palette}
      >
        {items.map((item, index) => (
          <details
            key={item.question}
            name={exclusive ? "vibeui-accordion-001" : undefined}
            open={index === defaultOpen}
          >
            <summary>
              {item.question}
              <span data-part="chevron" aria-hidden="true" />
            </summary>
            <p data-part="answer">{item.answer}</p>
          </details>
        ))}
      </div>
    </>
  )
}