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> ) }
openOnInit
If true, the collapsible will be open on initial render.
transTime
The time in it takes for each collapsible to expand and collapse. Default is 0ms.
transCurve
The timing function to use for the animation. Default is linear
.
initialHeight
The height in pixels to animate to and from. Defaults to 0
.
open
If 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.
classPrefix
Prepends onto onto every generated class name, useful for unique name-spacing within complex stylesheets.
isOpen
The current status of the collapsible.
rootClass
The 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.
id
A 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.
...settings
All 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> ) }
htmlElement
Customize the HTML element that is rendered in the DOM. Defaults to div
.
...rest
All 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> ) }
htmlElement
Customize the HTML element that is rendered in the DOM. Defaults to button
.
...rest
All 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> ) }
allowMultiple
When false, will close all collapsibles in the group when one is opened.
transTime
Standardizes all transition times of the collapsibles within the group. Can be overridden on each collapsible with the transTime
prop.
transCurve
Standardizes all transition curves of the collapsibles within the group. Can be overridden on each collapsible with the transCurve
prop.
classPrefix
Prepends onto onto every generated class name, useful for unique name-spacing within complex stylesheets.
toggleCount
The number of times the group has been toggled. Incremented every time a collapsible is opened or closed.
...settings
All settings are spread into the context.
This package strictly follows the WAI-ARIA pattern for accordions:
<CollapsibleContent>
has the following properties:
role
is region
aria-labelledby
is equal to the ID of the <CollapsibleToggler>
<CollapsibleToggler>
is a <button>
element with the following properties:
type
is button
aria-expanded
is toggled true
or false
based on isOpen
aria-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';