JGuang

Accordion

Accordion · Chakra UI

Preview
npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0

Accordion

Used to show and hide sections of related content on a page

Choose single or multiple expansion deliberately, keep stable item identifiers, and preserve trigger keyboard and expanded-state semantics. Avoid invalid nested buttons when adding actions.

Included icon notices

The source viewer includes ICON_ATTRIBUTION.md and original notices for the icon collections used by these examples. Preserve them when redistributing examples; react-icons' wrapper license does not replace individual collection terms.

  • Lucide: ISC

Installation and initialization

npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0

Initialize ChakraProvider with defaultSystem and Emotion before rendering. Preserve the host React version and inspect peer compatibility. Official npm installation supplies components, not these example source files. Use the resource setup guide for locale, next-themes and framework-specific SSR; copy the selected example source separately from npm installation.

Complete native usage example

This is the actual pinned example, not a generic API mock. Copy its source closure and retain the named export. Additional imports are listed per example below.

import { Accordion, Span } from "@chakra-ui/react"

export const AccordionBasic = () => {
  return (
    <Accordion.Root collapsible defaultValue={["b"]}>
      {items.map((item, index) => (
        <Accordion.Item key={index} value={item.value}>
          <Accordion.ItemTrigger>
            <Span flex="1">{item.title}</Span>
            <Accordion.ItemIndicator />
          </Accordion.ItemTrigger>
          <Accordion.ItemContent>
            <Accordion.ItemBody>{item.text}</Accordion.ItemBody>
          </Accordion.ItemContent>
        </Accordion.Item>
      ))}
    </Accordion.Root>
  )
}

const items = [
  { value: "a", title: "First Item", text: "Some value 1..." },
  { value: "b", title: "Second Item", text: "Some value 2..." },
  { value: "c", title: "Third Item", text: "Some value 3..." },
]

All examples and reproduction requirements

Names identify demos, not component variant props. Copy every sourceFiles entry for the selected example. The compositions alias denotes local files, not a package. Preserve relative imports or rewrite the alias to your project's actual path. React peers are inspected separately; editor examples retain the coherent pinned Tiptap extension family.

Basic

accordion-basic · Named export AccordionBasic · original upstream example

npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0
  • vendor/apps/compositions/src/examples/accordion-basic.tsx

Controlled

accordion-controlled · Named export AccordionControlled · original upstream example

npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0
  • vendor/apps/compositions/src/examples/accordion-controlled.tsx

With Icon

accordion-with-icon · Named export AccordionWithIcon · original upstream example

npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0 react-icons@5.6.0
  • vendor/apps/compositions/src/examples/accordion-with-icon.tsx

With Multiple

accordion-with-multiple · Named export AccordionWithMultiple · original upstream example

npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0
  • vendor/apps/compositions/src/examples/accordion-with-multiple.tsx

Sizes

accordion-sizes · Named export AccordionSizes · original upstream example

npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0
  • vendor/apps/compositions/src/examples/accordion-sizes.tsx

Variants

accordion-variants · Named export AccordionVariants · original upstream example

npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0
  • vendor/apps/compositions/src/examples/accordion-variants.tsx

With Disabled Item

accordion-with-disabled-item · Named export AccordionWithDisabledItem · original upstream example

npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0
  • vendor/apps/compositions/src/examples/accordion-with-disabled-item.tsx

With Avatar

accordion-with-avatar · Named export AccordionWithAvatar · original upstream example

npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0 prop-types@15.8.1 react-icons@5.6.0 react-lorem-ipsum@1.4.10
  • vendor/apps/compositions/src/examples/accordion-with-avatar.tsx

With Subtext

accordion-with-subtext · Named export AccordionWithSubtext · original upstream example

npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0 prop-types@15.8.1 react-lorem-ipsum@1.4.10
  • vendor/apps/compositions/src/examples/accordion-with-subtext.tsx

With Actions

accordion-with-actions · Named export AccordionWithActions · original upstream example

npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0 prop-types@15.8.1 react-lorem-ipsum@1.4.10
  • vendor/apps/compositions/src/examples/accordion-with-actions.tsx

With Expanded Style

accordion-with-expanded-style · Named export AccordionWithExpandedStyle · original upstream example

npm install @chakra-ui/react@3.37.0 @emotion/react@11.14.0
  • vendor/apps/compositions/src/examples/accordion-with-expanded-style.tsx

Native API and source references

The source viewer retains original declarations, imports and inheritance. Ark UI event contracts, Chakra style props and recipe types stay in their native packages; this guide does not flatten or invent their defaults. Code comments remain original source, not translated prose.

  • npm/@chakra-ui/react@3.37.0/dist/types/components/accordion/accordion.d.ts
  • npm/@chakra-ui/react@3.37.0/dist/types/components/accordion/index.d.ts
  • npm/@chakra-ui/react@3.37.0/dist/types/components/accordion/namespace.d.ts

Scoped Vite 8 interoperability

Some examples here import react-lorem-ipsum@1.4.10. The verified Vite 8 consumer uses the included authored/native-package-interop.mjs helper in its plugins list: chakraNativePackageInterop(process.cwd()). Copy that helper into the consuming build config and adjust the import path. This unwraps the package's native CommonJS default; it does not replace the component. Apply only when this export mismatch is reproduced; other bundlers may not need it.

State and installation checks

Run strict types, the target production build and real interactions. Test labels/focus/keyboard, both themes, narrow layout, empty/loading/error states where supported and cleanup after unmount. Remote demo endpoints, uploads and downloads are constrained in the preview; configure your own services. Copying a command or reaching preview-ready does not prove installation or backend success.

Provenance and license boundaries

https://github.com/chakra-ui/chakra-ui/tree/2e7517745cff2fcde0b8012f136cf99611ff262a

These are JGuang practical bilingual notes, not a full translation of upstream MDX. Original documentation and example bytes remain in vendor. Preserve repository MIT, compositions ISC metadata and separate dependency notices. The original metadata discrepancy and any missing full notices remain explicit review items; paid Chakra Pro is excluded.