Layout
Accordion A vertically stacked set of collapsible sections that reveal content on demand.
npm pnpm yarn bun
npm install @morphos/layout
import { Accordion, AccordionItem, AccordionTrigger, AccordionContent } from '@morphos/layout'
@ Component ()
class MyComponent extends StatefulComponent {
@ State () accordion = new Accordion ({ type: 'single' , collapsible: true })
render () {
return (
< Accordion accordion = { this .accordion}>
< AccordionItem accordion = { this .accordion} value = "item-1" >
< AccordionTrigger accordion = { this .accordion} item = "item-1" >
What is Morphos?
</ AccordionTrigger >
< AccordionContent accordion = { this .accordion} item = "item-1" >
Morphos is a headless PraxisJS component library.
</ AccordionContent >
</ AccordionItem >
< AccordionItem accordion = { this .accordion} value = "item-2" >
< AccordionTrigger accordion = { this .accordion} item = "item-2" >
Is it accessible?
</ AccordionTrigger >
< AccordionContent accordion = { this .accordion} item = "item-2" >
Yes — it follows WAI-ARIA authoring practices.
</ AccordionContent >
</ AccordionItem >
</ Accordion >
)
}
}
Set type="multiple" on the Accordion instance to allow any number of items open simultaneously instead of only one.
Component Description AccordionRoot state manager — tracks which item(s) are expanded AccordionItemA single collapsible section AccordionTriggerThe button that toggles an item open or closed AccordionContentThe content revealed when an item is expanded
Prop Type Default Description type"single" | "multiple""single"Whether one or many items can be open at once valuestring | string[]— Controlled expanded item(s) defaultValuestring | string[]— Initially expanded item(s) (uncontrolled) onValueChange(value: string | string[]) => void— Called when expanded items change collapsiblebooleantrueWhether an open item can be collapsed by clicking it again (only meaningful for type="single") classstring— CSS class idstring— HTML id
Method Description isOpen(item: string)Returns whether the given item value is currently expanded toggle(item: string)Opens or closes the given item, following the type/collapsible rules
Prop Type Default Description accordionAccordion— The Accordion state instance valuestring— Unique identifier for this item disabledboolean— Marks the item as disabled (exposed via data-disabled; does not itself block interaction) classstring— CSS class idstring— HTML id
Prop Type Default Description accordionAccordion— The Accordion state instance itemstring— The value of the parent AccordionItem childrenChildren— Trigger label classstring— CSS class idstring— HTML id (defaults to an auto-generated id)
Prop Type Default Description accordionAccordion— The Accordion state instance itemstring— The value of the parent AccordionItem childrenChildren— Content to reveal classstring— CSS class idstring— HTML id
Attribute Element When present data-typeAccordion Always — reflects the type prop ("single" or "multiple") data-expandedAccordionItem, AccordionTrigger, AccordionContent The item is expanded data-disabledAccordionItem The item's disabled prop is set
AccordionTrigger handles Enter and Space to toggle the item, in addition to onClick. Arrow-key navigation between triggers is not built in — each trigger is a regular tab-stop.
.morphos-accordion-trigger [ data-expanded ] ::after {
transform : rotate ( -135 deg );
}
.morphos-accordion-item:last-child {
border-bottom : none ;
}