组件

Collapsible

One panel that folds away behind a trigger. Minimal by design: the panel slides, and if you ask for it, writes a margin brace beside its text. The chevron indicator turns over the same way the accordion's does.

安装

terminal
npx shadcn@latest add @wobko/collapsible

第一次使用?先把 registry 加进 components.json。 如何安装

示例

Starred repositories

The classic: a heading with a trigger button, one item always shown and the rest folded away. The panel slides open and shut.

Margin bracket and indicator

`bracket` writes a brace beside the opened text and lets it soak in; `CollapsibleIndicator` is the same chevron as the accordion's and turns over with the panel.

Show more

A composed card: the first three lines of a reading list are always there, the rest fold away behind a controlled trigger that says what it will do.

API 参考

Collapsible

The Radix Collapsible root (also `group/collapsible`, for your own state-dependent classes).

属性类型默认值说明
open / defaultOpen / onOpenChangeboolean / boolean / (open: boolean) => void-Controlled and uncontrolled state.
disabledbooleanfalseThe trigger stops toggling.

CollapsibleContent

The panel. It slides open and shut with a height animation that clips the text only while it moves, so a focus ring or ink bleed inside an open panel is never cut (upstream's animated `overflow-hidden` cuts it for good).

属性类型默认值说明
bracket"curly" | "square" | falsefalseDraw a margin bracket beside the opened content and let the text soak in. Wraps the children in one element.

无障碍

  • The trigger is a button with `aria-expanded` and `aria-controls`; Enter and Space toggle it. Closed content is not rendered.
  • Give the trigger a name: visible text, or a `sr-only` span when it is an icon button.
  • The brace and the chevron are decoration (aria-hidden); state is told by aria-expanded.
  • Reduced motion opens and closes the panel at once.

源码

CLI 会复制进你项目的文件。

正在加载源码