David UI's Collapse component provides an elegant solution for organizing content in expandable sections. Styled with Tailwind CSS, it supports smooth transitions, icons, and fully customizable designs.
Explore our responsive Collapse component examples, styled with Tailwind CSS, which are perfect for enhancing usability in your web or mobile projects.
This component is ideal for building features like accordions, mobile menus, file trees, and more. Copy and paste the code below directly into your project.
Some placeholder content for the collapse component. This panel is hidden by default but revealed when the user activates the relevant trigger.
Check out this example to discover how to design a responsive collapse component tailored for various use cases.
The Collapse component in david-ai requires JavaScript to handle the expand/collapse functionality. The library provides smooth transitions and toggle behavior through data attributes.
To use the Collapse component in your project, you first need to install the david-ai
library via npm:
If you prefer, you can use the DavidAI global object instead of directly importing initCollapse:
You can include david-ai via a CDN and initialize collapse functionality globally in the browser. Add the following script to your HTML file:
David AI Collapse component can be used programmatically with TypeScript support for more control and type safety:
Learn how to use David AI's Collapse component with TypeScript for dynamic content toggling. This component provides programmatic methods to expand, collapse and animate content with full type safety and customization options.
The HTML structure demonstrates an accessible and interactive collapse component featuring:
Here's the complete HTML implementation:
The Collapse component provides a way to toggle the visibility of content with smooth animations and accessibility features. It supports icon rotation and programmatic control through methods like toggle, expand, and collapse.
Interface | Property/Method | Type | Description |
---|---|---|---|
CollapseConfig | iconSelector | string (optional) | Selector for the icon element to toggle rotation. For example, you can pass "[data-icon]" to target specific icons. |
ICollapse | toggle() | void | Toggles the collapsible content visibility. |
ICollapse | expand() | void | Expands the collapsible content. |
ICollapse | collapse() | void | Collapses the collapsible content. |