npm_versionnpm Paragon package page

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 VariableComputed Value
‌
‌
‌
‌
‌
‌
‌
‌
‌
‌

Props API#

Collapsible Props API
  • children React.ReactNode Required

    Specifies contents of the component.

  • className string

    Specifies class name to append to the base element.

  • defaultOpen boolean

    Specifies whether the Collapsible should be initially open.

    Defaultfalse
  • iconWhenClosed React.ReactElement | null

    Specifies icon to show when Collapsible is closed. Pass null to hide the icon.

    Default<Icon src={ExpandMore} />
  • iconWhenOpen React.ReactElement | null

    Specifies icon to show when Collapsible is open. Pass null to hide the icon.

    Default<Icon src={ExpandLess} />
  • onClose () => void

    Callback fired when Collapsible closes.

  • onOpen () => void

    Callback fired when Collapsible opens.

  • onToggle (isOpen: boolean) => void

    Callback fired when Collapsible's state is toggled.

  • open boolean

    Specifies whether Collapsible is open.

  • styling 'basic' | 'card' | 'card-lg'

    Specifies style variant.

    Default'card'
  • title React.ReactNode Required

    Specifies title.

  • unmountOnExit boolean

    Unmount the component (remove it from the DOM) when it is collapsed

    Defaulttrue
CollapsibleAdvanced Props API
  • children React.ReactNode

    Specifies contents of the component.

  • className string

    Specifies classname to append to the base element.

  • defaultOpen boolean

    Specifies whether Collapsible should be initially open.

  • open boolean

    Specifies whether Collapsible is open.

  • onToggle (isOpen: boolean) => void

    Callback fired when Collapsible's state is toggled.

  • onOpen () => void

    Callback fired when Collapsible opens.

  • onClose () => void

    Callback fired when Collapsible closes.

  • unmountOnExit boolean

    Unmount the component (remove it from the DOM) when it is collapsed.

CollapsibleBody Props API
  • children React.ReactNode

    Specifies contents of the component.

  • tag string

    Specifies content's base element.

    Default'div'
  • transitionWrapper React.ReactElement

    Specifies transition element.

CollapsibleTrigger Props API
  • children React.ReactNode

    Specifies contents of the component.

  • tag string | React.ElementType

    Specifies base element.

    Default'div'
  • openOnly boolean

    Specifies whether toggling Collapsible's state will always trigger only open action.

    Defaultfalse
  • closeOnly boolean

    Specifies whether toggling Collapsible's state will always trigger only close action.

    Defaultfalse
  • onClick (e: React.MouseEvent) => void

    Callback fired when element gets clicked.

  • onKeyDown (e: React.KeyboardEvent) => void

    Callback fired when a key is pressed.

CollapsibleVisible Props API
  • children React.ReactNode

    Specifies contents of the component.

  • whenOpen boolean

    Specifies whether the content should be visible when Collapsible is open.

    Defaultfalse
  • whenClosed boolean

    Specifies whether the content should be visible when Collapsible is closed.

    Defaultfalse

Usage Insights#

Collapsible

Project NameParagon VersionInstance Count
frontend-app-account22.10.04
frontend-app-admin-portal21.13.111
frontend-app-communications22.7.02
frontend-app-course-authoring22.8.14
frontend-app-gradebook22.8.14
frontend-app-learner-portal-enterprise21.13.14
frontend-app-learner-portal-programs21.13.11
frontend-app-learning22.10.02
frontend-app-ora-grading21.11.31
frontend-app-payment22.9.01
frontend-app-program-console21.13.12
frontend-app-publisher21.13.11
frontend-component-header-edx21.13.11
frontend-component-header22.10.01
frontend-learner-portal-base12.2.01
prospectus20.46.224

CollapsibleAdvanced

Project NameParagon VersionInstance Count
frontend-app-account22.10.01
frontend-app-course-authoring22.8.113
frontend-app-discussions22.7.03
frontend-app-learner-portal-enterprise21.13.12
frontend-app-learning22.10.03
frontend-app-ora-grading21.11.31
frontend-app-publisher21.13.11
prospectus20.46.24

CollapsibleBody

Project NameParagon VersionInstance Count
frontend-app-account22.10.01
frontend-app-course-authoring22.8.111
frontend-app-discussions22.7.03
frontend-app-learner-portal-enterprise21.13.12
frontend-app-learning22.10.03
frontend-app-ora-grading21.11.31
prospectus20.46.24

CollapsibleTrigger

Project NameParagon VersionInstance Count
frontend-app-account22.10.01
frontend-app-course-authoring22.8.18
frontend-app-discussions22.7.03
frontend-app-learner-portal-enterprise21.13.12
frontend-app-learning22.10.03
frontend-app-ora-grading21.11.31
frontend-app-publisher21.13.11
prospectus20.46.22

CollapsibleVisible

Project NameParagon VersionInstance Count
frontend-app-course-authoring22.8.112
frontend-app-discussions22.7.06
frontend-app-learner-portal-enterprise21.13.14
frontend-app-learning22.10.06
frontend-app-ora-grading21.11.32
frontend-app-publisher21.13.12
prospectus20.46.28