Fragiola

API: components

Accordion

Stacked headers that show and hide their sections, one or several open, with arrow-key navigation, following the APG accordion pattern, in each framework.

Stacked headers, each showing and hiding a section of content (WAI-ARIA APG accordion pattern): one section open at a time, or several with multiple. Its panels have a Collapsible's mechanics: size variables for a height transition with no layout jump, enter and exit states, keepMounted and hiddenUntilFound.

FAQ
Gallery

Behaviour

  • Toggle: a click on a Trigger, Enter or Space. Without multiple, opening an item closes the open one; an open item's Trigger closes it in both modes.
  • Keyboard: the arrows along the orientation (mirrored in RTL when horizontal), Home and End move among the enabled Triggers, wrapping with loopFocus. Every enabled Trigger is a tab stop.
  • Value: the values of the open items, an array of strings in every mode.
  • Headings: each Header is an h3 (give another level with render); each Panel is a region named by its Trigger.
  • Animation and find in page: as a Collapsible's, with --accordion-panel-height and --accordion-panel-width; a find-in-page match opens its item (reason none).

Anatomy

partelementdata-primitives-partrole
Rootdivaccordion-rootholds the value
Itemdivaccordion-itemone section
Headerh3accordion-headerthe heading around the Trigger
Triggerbuttonaccordion-triggerthe header's button
Paneldivaccordion-panelthe section's region

Usage

import { Accordion } from "@fragiola/primitives-react/accordion";

<Accordion.Root defaultValue={["shipping"]}>
    <Accordion.Item value="shipping">
        <Accordion.Header>
            <Accordion.Trigger>Shipping</Accordion.Trigger>
        </Accordion.Header>
        <Accordion.Panel hiddenUntilFound>Ships within two business days.</Accordion.Panel>
    </Accordion.Item>
</Accordion.Root>;

Props

Every part also takes what the primitive contract gives. The names below are React's; Vue binds them as v-model:value and @value-change, Angular as [(value)] and (valueChangeDetails).

Root

proptypedefaultdescription
valuestring[]the open items, controlled
defaultValuestring[][]the initially open items, uncontrolled
onValueChange(value: string[], details: { reason }) => voidevery change (trigger-press, or none for a find-in-page match)
multiplebooleanfalseseveral items may be open
disabledbooleanfalseevery item is disabled
orientation"vertical" | "horizontal""vertical"which arrow keys move between the Triggers
loopFocusbooleantruewhether the arrow keys wrap around

Item

proptypedefaultdescription
valuestringrequired: the item's value
disabledbooleanfalseits Trigger is disabled and skipped by the arrows

No props of its own.

Trigger

No props of its own.

Panel

proptypedefaultdescription
keepMounted (react, vue)booleanfalsekeep a closed panel in the DOM, hidden
hiddenUntilFound (react, vue)booleanfalsekeep a closed panel in the DOM, hidden="until-found", searchable
options (angular){ keepMounted?, hiddenUntilFound? }{}the same two options: *accordionPanel="{ keepMounted: true }"

State and part attributes

partattributes
Rootdata-orientation, data-disabled
Itemdata-open / data-closed, data-disabled, data-orientation
Headerdata-open / data-closed, data-disabled
Triggerid, aria-expanded, aria-controls while open, disabled and data-disabled, data-panel-open
Panelrole="region", id, aria-labelledby, data-open / data-closed, data-disabled, data-orientation, data-starting-style / data-ending-style, hidden (or hidden="until-found") while closed and kept, --accordion-panel-height, --accordion-panel-width

Keyboard

keyverticalhorizontal
Enter, Spacetoggles the itemthe same
next TriggerArrowDownArrowRight (ArrowLeft in RTL)
previous TriggerArrowUpArrowLeft (ArrowRight in RTL)
Home, Endthe first, the last Triggerthe same

Exports

entryexports
@fragiola/primitives-react/accordionAccordion, AccordionRootProps, AccordionRootState, AccordionItemProps, AccordionItemState, AccordionHeaderProps, AccordionTriggerProps, AccordionPanelProps, AccordionPanelState, AccordionOrientation, ChangeDetails, ChangeReason, RenderProp
@fragiola/primitives-vue/accordionAccordion, AccordionRootProps, AccordionRootEmits, AccordionRootState, AccordionItemProps, AccordionItemState, AccordionPanelProps, AccordionPanelState, AccordionOrientation, ChangeDetails, ChangeReason, RenderSlotProps
@fragiola/primitives-angular/accordionAccordionRoot, AccordionItem, AccordionHeader, AccordionTrigger, AccordionPanel, AccordionRootState, AccordionItemState, AccordionPanelOptions, AccordionPanelState, AccordionOrientation, ChangeDetails, ChangeReason, TransitionStatus, ValueChangeEvent