Fragiola

API: components

Collapsible

A button that shows and hides one panel, animatable in CSS with no layout jump and searchable while closed (APG disclosure), in each framework.

A button that shows and hides one section of content (WAI-ARIA APG disclosure pattern). The panel exposes its content's size as CSS variables and its enter and exit states, so a height transition plays with no layout jump; a closed panel can stay searchable by the browser's find-in-page (hiddenUntilFound). Several sections with keyboard navigation between their headers are an Accordion.

Settings sidebar
Gallery

Behaviour

  • Toggle: a click on the Trigger, Enter or Space (a native button). Opening and closing never move focus.
  • Disabled: the Trigger is a disabled button; only a controlled open changes the state.
  • Animation: --collapsible-panel-height and --collapsible-panel-width are auto at rest and the content's size in pixels while the panel opens or closes, written before the transition starts. Transition height: var(--collapsible-panel-height) between data-starting-style / data-ending-style at height: 0 and it never starts from auto. A panel open on the first render (and on a server) plays no transition.
  • Closed panels: not rendered; with keepMounted, kept with hidden; with hiddenUntilFound, kept with hidden="until-found".
  • Find in page (hiddenUntilFound, Chromium): a match in a closed panel opens it at once (onOpenChange(true, { reason: "none" }), no transition). A controlled Root that keeps open false gets hidden="until-found" back. Other browsers treat the attribute as hidden.

Anatomy

partelementdata-primitives-partrole
Rootdivcollapsible-rootholds the open state
Triggerbuttoncollapsible-triggerthe disclosure button
Paneldivcollapsible-panelthe content shown and hidden

Usage

import { Collapsible } from "@fragiola/primitives-react/collapsible";

<Collapsible.Root defaultOpen>
    <Collapsible.Trigger>Recovery keys</Collapsible.Trigger>
    <Collapsible.Panel hiddenUntilFound>
        <p>alpha-1234</p>
    </Collapsible.Panel>
</Collapsible.Root>;

Props

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

Root

proptypedefaultdescription
openbooleanthe open state, controlled
defaultOpenbooleanfalsethe initial state, uncontrolled
onOpenChange(open: boolean, details: { reason }) => voidevery change (trigger-press, or none for a find-in-page match)
disabledbooleanfalsethe Trigger is disabled

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: *collapsiblePanel="{ hiddenUntilFound: true }"

State and part attributes

partattributes
Rootdata-open / data-closed, data-disabled
Triggeraria-expanded, aria-controls while open, disabled and data-disabled, data-panel-open
Panelid, data-open / data-closed, data-disabled, data-starting-style / data-ending-style, hidden (or hidden="until-found") while closed and kept, --collapsible-panel-height, --collapsible-panel-width

Keyboard

keyaction
Enter, Spacetoggles the panel
Tabmoves on

Exports

entryexports
@fragiola/primitives-react/collapsibleCollapsible, CollapsibleRootProps, CollapsibleState, CollapsibleTriggerProps, CollapsiblePanelProps, CollapsiblePanelState, ChangeDetails, ChangeReason, RenderProp
@fragiola/primitives-vue/collapsibleCollapsible, CollapsibleRootProps, CollapsibleRootEmits, CollapsibleState, CollapsiblePanelProps, CollapsiblePanelState, ChangeDetails, ChangeReason, RenderSlotProps
@fragiola/primitives-angular/collapsibleCollapsibleRoot, CollapsibleTrigger, CollapsiblePanel, CollapsibleState, CollapsiblePanelOptions, CollapsiblePanelState, ChangeDetails, ChangeReason, OpenChangeEvent, TransitionStatus