David UI's accordion component is built with Tailwind CSS and HTML to create sleek expand/collapse sections. Perfect for FAQs, menus, and content toggling, it provides an interactive way to organize information.
Customize styles effortlessly and explore examples to integrate this versatile, responsive component into your design.
Create an SEO-optimized accordion component with exclusive mode using data-dui-accordion-mode="exclusive"
. This ensures only one section stays open at a time, ideal for FAQ pages and content organization. The semantic HTML and ARIA attributes enhance both accessibility and search engine visibility while providing an excellent user experience.
David UI is a comprehensive UI library built with Tailwind CSS, offering modern and customizable components for web development.
David UI provides an extensive collection of ready-to-use components with seamless integration and excellent developer experience.
Enhance content accessibility and SEO with the "all-open" accordion mode. Using data-dui-accordion-mode="all-open"
allows users to view multiple sections simultaneously while maintaining collapse functionality. This feature optimizes content visibility and user engagement by displaying information upfront. Ideal for documentation and content-rich pages, the semantic HTML and ARIA attributes ensure proper accessibility and search engine indexing.
David UI is a comprehensive UI library built with Tailwind CSS, offering modern and customizable components for web development.
David UI provides an extensive collection of ready-to-use components with seamless integration and excellent developer experience.
The Accordion component can operate in both controlled and uncontrolled modes. In controlled mode, you have full control over its state using the value
and onValueChange
properties.
David UI is a comprehensive UI library built with Tailwind CSS, offering modern and customizable components for web development.
David UI provides an extensive collection of ready-to-use components with seamless integration and excellent developer experience.
Customize the accordion's toggle icons using data-dui-accordion-icon-close
and data-dui-accordion-icon-open
attributes. These allow you to seamlessly switch between different icons based on the accordion's open/closed state, enhancing visual feedback and user experience.
David UI is a comprehensive UI library built with Tailwind CSS, offering modern and customizable components for web development.
David UI provides an extensive collection of ready-to-use components with seamless integration and excellent developer experience.
Tailor the appearance of your Accordion by applying styles through the className
property. The example demonstrates how to design a unique look for the Accordion component.
David UI is a comprehensive UI library built with Tailwind CSS, offering modern and customizable components for web development.
David UI provides an extensive collection of ready-to-use components with seamless integration and excellent developer experience.
Enhance accessibility and user experience by disabling specific accordion sections using aria-disabled="true"
. This attribute prevents user interaction and clearly indicates non-interactive content, improving both SEO and usability. Disabled sections maintain visual consistency while being properly marked up for screen readers and search engines.
David UI is a comprehensive UI library built with Tailwind CSS, offering modern and customizable components for web development.
David UI provides an extensive collection of ready-to-use components with seamless integration and excellent developer experience.
The Accordion component in david-ai requires JavaScript to handle the accordion functionality. The library provides smooth transitions and collapse/expand behavior through data attributes.
To use the Accordion 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 initAccordion:
You can include david-ai via a CDN and initialize accordion functionality globally in the browser. Add the following script to your HTML file:
David AI Accordion component can be used programmatically with TypeScript support for more control and type safety:
Learn how to use David AI's Accordion component with TypeScript for dynamic section toggling. This component provides programmatic methods to open, close and control accordion sections with full type safety and customization options.
The HTML structure demonstrates an accessible and interactive accordion component featuring:
Here's the complete HTML implementation:
The Accordion component provides a way to create collapsible content sections with smooth animations and accessibility features. It supports exclusive mode where only one section can be open at a time, as well as programmatic control through methods like toggle, show, hide, showAll, and hideAll.
Interface | Property/Method | Type | Description |
---|---|---|---|
AccordionConfig | exclusive | boolean (optional) | When true, only one section can be open at a time. Default is false. |
AccordionConfig | allOpen | boolean (optional) | When true, allows multiple sections to be open simultaneously. Default is false. |
IAccordion | toggle(element) | void | Toggles the open/closed state of an accordion section. Element can be HTMLElement or string ID. |
IAccordion | show(element) | void | Opens an accordion section. Element can be HTMLElement or string ID. |
IAccordion | hide(element) | void | Closes an accordion section. Element can be HTMLElement or string ID. |
IAccordion | showAll() | void | Opens all accordion sections simultaneously. |
IAccordion | hideAll() | void | Closes all accordion sections simultaneously. |
IAccordion | cleanup() | void | Removes all event listeners and cleans up the accordion instance. |