Collapsible
Collapsible is an element that allows a user to toggle (view/hide) supplemental information or actions.
When to use:
- To organize related information.
- To shorten pages and reduce scrolling when content is not crucial to read in full.
- When space is at a premium and long content cannot be displayed all at once.
Basic Usage
The styling prop at the top level <Collapsible /> component determines if the collapsible has basic styling, card, or card with heading.
Basic Style
Any Paragon component or export may be added to the code example.
Card Style
This is the default style if no styling prop is supplied.
Any Paragon component or export may be added to the code example.
Default Open
Any Paragon component or export may be added to the code example.
With Callbacks
Any Paragon component or export may be added to the code example.
Advanced Usage
For needs that deviate from the three styles above, use <Collapsible.Advanced />
Bare minimum
Any Paragon component or export may be added to the code example.
Card style with advanced usage
Any Paragon component or export may be added to the code example.
With a close button
Any Paragon component or export may be added to the code example.
onOpen, onClose and onToggle callbacks
See the developer console for logging.
Any Paragon component or export may be added to the code example.
Controlled usage
Any Paragon component or export may be added to the code example.
Imperative methods
If you need to open or close the Collapsible intermittently due to an event,
such as loading the page or clicking a link, you can open or close
an uncontrolled Collapsible by getting a ref to the component and calling
collapsibleRef.open() or collapsibleRef.close(). The internal state of
the component will be updated accordingly.
Theme Variables#
| CSS Variable | Computed Value |
|---|---|
| | |
| | |
| | |
| | |
| | |
Props API#
- children
React.ReactNodeRequiredSpecifies contents of the component.
- className
stringSpecifies class name to append to the base element.
- defaultOpen
booleanDefaultfalseSpecifies whether the
Collapsibleshould be initially open. - iconWhenClosed
React.ReactElement|nullDefault<Icon src={ExpandMore} />Specifies icon to show when
Collapsibleis closed. Passnullto hide the icon. - iconWhenOpen
React.ReactElement|nullDefault<Icon src={ExpandLess} />Specifies icon to show when
Collapsibleis open. Passnullto hide the icon. - onClose
() => voidCallback fired when
Collapsiblecloses. - onOpen
() => voidCallback fired when
Collapsibleopens. - onToggle
(isOpen: boolean) => voidCallback fired when
Collapsible'sstate is toggled. - open
booleanSpecifies whether
Collapsibleis open. - styling
'basic'|'card'|'card-lg'Default'card'Specifies style variant.
- title
React.ReactNodeRequiredSpecifies title.
- unmountOnExit
booleanDefaulttrueUnmount the component (remove it from the DOM) when it is collapsed
- children
React.ReactNodeSpecifies contents of the component.
- className
stringSpecifies classname to append to the base element.
- defaultOpen
booleanSpecifies whether
Collapsibleshould be initially open. - open
booleanSpecifies whether
Collapsibleis open. - onToggle
(isOpen: boolean) => voidCallback fired when
Collapsible'sstate is toggled. - onOpen
() => voidCallback fired when
Collapsibleopens. - onClose
() => voidCallback fired when
Collapsiblecloses. - unmountOnExit
booleanUnmount the component (remove it from the DOM) when it is collapsed.
- children
React.ReactNodeSpecifies contents of the component.
- tag
stringDefault'div'Specifies content's base element.
- transitionWrapper
React.ReactElementSpecifies transition element.
- children
React.ReactNodeSpecifies contents of the component.
- tag
string|React.ElementTypeDefault'div'Specifies base element.
- openOnly
booleanDefaultfalseSpecifies whether toggling
Collapsible'sstate will always trigger only open action. - closeOnly
booleanDefaultfalseSpecifies whether toggling
Collapsible'sstate will always trigger only close action. - onClick
(e: React.MouseEvent) => voidCallback fired when element gets clicked.
- onKeyDown
(e: React.KeyboardEvent) => voidCallback fired when a key is pressed.
- children
React.ReactNodeSpecifies contents of the component.
- whenOpen
booleanDefaultfalseSpecifies whether the content should be visible when
Collapsibleis open. - whenClosed
booleanDefaultfalseSpecifies whether the content should be visible when
Collapsibleis closed.
Usage Insights#
Collapsible
| Project Name | Paragon Version | Instance Count | |
|---|---|---|---|
| frontend-app-account | 22.10.0 | 4 | |
| frontend-app-admin-portal | 21.13.1 | 11 | |
| frontend-app-communications | 22.7.0 | 2 | |
| frontend-app-course-authoring | 22.8.1 | 4 | |
| frontend-app-gradebook | 22.8.1 | 4 | |
| frontend-app-learner-portal-enterprise | 21.13.1 | 4 | |
| frontend-app-learner-portal-programs | 21.13.1 | 1 | |
| frontend-app-learning | 22.10.0 | 2 | |
| frontend-app-ora-grading | 21.11.3 | 1 | |
| frontend-app-payment | 22.9.0 | 1 | |
| frontend-app-program-console | 21.13.1 | 2 | |
| frontend-app-publisher | 21.13.1 | 1 | |
| frontend-component-header-edx | 21.13.1 | 1 | |
| frontend-component-header | 22.10.0 | 1 | |
| frontend-learner-portal-base | 12.2.0 | 1 | |
| prospectus | 20.46.2 | 24 |
CollapsibleAdvanced
| Project Name | Paragon Version | Instance Count | |
|---|---|---|---|
| frontend-app-account | 22.10.0 | 1 | |
| frontend-app-course-authoring | 22.8.1 | 13 | |
| frontend-app-discussions | 22.7.0 | 3 | |
| frontend-app-learner-portal-enterprise | 21.13.1 | 2 | |
| frontend-app-learning | 22.10.0 | 3 | |
| frontend-app-ora-grading | 21.11.3 | 1 | |
| frontend-app-publisher | 21.13.1 | 1 | |
| prospectus | 20.46.2 | 4 |
CollapsibleBody
| Project Name | Paragon Version | Instance Count | |
|---|---|---|---|
| frontend-app-account | 22.10.0 | 1 | |
| frontend-app-course-authoring | 22.8.1 | 11 | |
| frontend-app-discussions | 22.7.0 | 3 | |
| frontend-app-learner-portal-enterprise | 21.13.1 | 2 | |
| frontend-app-learning | 22.10.0 | 3 | |
| frontend-app-ora-grading | 21.11.3 | 1 | |
| prospectus | 20.46.2 | 4 |
CollapsibleTrigger
| Project Name | Paragon Version | Instance Count | |
|---|---|---|---|
| frontend-app-account | 22.10.0 | 1 | |
| frontend-app-course-authoring | 22.8.1 | 8 | |
| frontend-app-discussions | 22.7.0 | 3 | |
| frontend-app-learner-portal-enterprise | 21.13.1 | 2 | |
| frontend-app-learning | 22.10.0 | 3 | |
| frontend-app-ora-grading | 21.11.3 | 1 | |
| frontend-app-publisher | 21.13.1 | 1 | |
| prospectus | 20.46.2 | 2 |
CollapsibleVisible
| Project Name | Paragon Version | Instance Count | |
|---|---|---|---|
| frontend-app-course-authoring | 22.8.1 | 12 | |
| frontend-app-discussions | 22.7.0 | 6 | |
| frontend-app-learner-portal-enterprise | 21.13.1 | 4 | |
| frontend-app-learning | 22.10.0 | 6 | |
| frontend-app-ora-grading | 21.11.3 | 2 | |
| frontend-app-publisher | 21.13.1 | 2 | |
| prospectus | 20.46.2 | 8 |