This component provides a new collapsible context to any section of your app. It has no required props and renders nothing in the DOM. This is where the collapsible settings are defined.
import React from 'react'; import { Collapsible } from '@faceless-ui/collapsibles'; export const MyComponent = () => { return ( <Collapsible openOnInit transTime={250} transCurve="linear" onToggle={() => { console.log('toggled') }} // open={false} NOTE: can also be used to control a collapsible > ... </Collapsible> ) }
openOnInitIf true, the collapsible will be open on initial render.
transTimeThe time in it takes for each collapsible to expand and collapse. Default is 0ms.
transCurveThe timing function to use for the animation. Default is linear.
initialHeightThe height in pixels to animate to and from. Defaults to 0.
openIf true, the collapsible will be open. This is a useful pattern to control the collapsible with external state.
onToggle()A callback function that is executed when the collapsible is toggled.
classPrefixPrepends onto onto every generated class name, useful for unique name-spacing within complex stylesheets.
isOpenThe current status of the collapsible.
rootClassThe root class for the collapsible. Appends classPrefix to the class name, when defined.
handleClick()Used internally to report the toggle to the nearest <CollapsibleGroup>, if nested.
idA unique ID used to match ARIA attributes between the collapsible components. Defaults to a random string using the useId hook. See accessibility for full details.
...settingsAll settings are spread into the context.
The height of this component will be animated from 0 to auto-height content when the collapsible is triggered. This is made possible through react-animate-height. This component has no required props.
import React from 'react'; import { Collapsible, CollapsibleContent } from '@faceless-ui/collapsibles'; export const MyComponent = () => { return ( <Collapsible> <CollapsibleContent> ... </CollapsibleContent> </Collapsible> ) }
htmlElementCustomize the HTML element that is rendered in the DOM. Defaults to div.
...restAll other props are spread onto the DOM element as HTML attributes.
This component renders a button that opens and closes the nearest collapsible when clicked.
import React from 'react'; import { Collapsible, CollapsibleToggler } from '@faceless-ui/collapsibles'; export const MyComponent = () => { return ( <Collapsible> <CollapsibleToggler> ... </CollapsibleToggler> </Collapsible> ) }
htmlElementCustomize the HTML element that is rendered in the DOM. Defaults to button.
...restAll other props are spread onto the DOM element as HTML attributes.
This component provides a new group context to any section of your app. It has no required props and renders nothing in the DOM. This is where the group settings are defined.
import React from 'react'; import { CollapsibleGroup, Collapsible, CollapsibleContent } from '@faceless-ui/collapsibles'; export const MyComponent = () => { return ( <CollapsibleGroup allowMultiple={false}> <Collapsible openOnInit> ... </Collapsible> <Collapsible> ... </Collapsible> </CollapsibleGroup> ) }
allowMultipleWhen false, will close all collapsibles in the group when one is opened.
transTimeStandardizes all transition times of the collapsibles within the group. Can be overridden on each collapsible with the transTime prop.
transCurveStandardizes all transition curves of the collapsibles within the group. Can be overridden on each collapsible with the transCurve prop.
classPrefixPrepends onto onto every generated class name, useful for unique name-spacing within complex stylesheets.
toggleCountThe number of times the group has been toggled. Incremented every time a collapsible is opened or closed.
...settingsAll settings are spread into the context.
This package strictly follows the WAI-ARIA pattern for accordions:
<CollapsibleContent> has the following properties:
role is regionaria-labelledby is equal to the ID of the <CollapsibleToggler><CollapsibleToggler> is a <button> element with the following properties:
type is buttonaria-expanded is toggled true or false based on isOpenaria-owns is equal to the ID of the <CollapsibleContent>aria-label is "toggle collapsible" by defaultNOTE: To match ARIA attributes between DOM elements, a random string is generated using the useId hook. To opt out of this, just pass your own id to the <Collapsible> and it will be used instead.
All types can be directly imported.
import { CollapsibleProps, ICollapsibleContext, CollapsibleContentProps, CollapsibleTogglerProps, ICollapsibleGroupContext, CollapsibleGroupProps } from '@faceless-ui/collapsibles/dist/types';