Collapsible
A Collapsible is a section that can be toggled open and closed. It is typically grouped with other Collapsibles into an Accordion.
Playground
Each collapsible has a summary (aka the heading). When the summary is clicked, the collapsible opens or closes, revealing or hiding the collapsible's content.
<BasicCollapsible heading="Summary">Content</BasicCollapsible>
<div class="collapsible"><div class="collapsible-summary"><!-- doesn't have to be a <div> tag; use <h1>-<h6> if appropriate --><buttonclass="collapsible-summary-button"aria-expanded="false"aria-controls="myExampleAccordionContent">Summary</button></div><div class="collapsible-content" id="myExampleAccordionContent">Content</div></div>
StepCollapsible
If you are using an Accordion with the "steps" skin, and are using React Visage, then you'll want to use StepCollapsible
instead of BasicCollapsible
inside that Accordion
. StepCollapsible
is a convenience component to make it easier to set up the sub-components inside the collapsible's summary.
React Convenience Components
React Visage provides BasicCollapsible
and StepCollapsible
as a convenience for the most common use-cases.
Each is simply created by combining basic components together, so if you find that the Convenience Component isn't exactly what you need, you can easily compose your own version!
BasicCollapsible
BasicCollapsible has no props of its own
What's Under the Hood?
<Collapsible {...props}><CollapsibleSummary><CollapsibleSummaryButton>{heading}</CollapsibleSummaryButton></CollapsibleSummary><CollapsibleContent>{children}</CollapsibleContent></Collapsible>
StepCollapsible
What's Under the Hood?
<Collapsible {...props}><CollapsibleSummary><CollapsibleSummaryButton><CollapsibleSummaryButtonStepNumber>{stepNumber}</CollapsibleSummaryButtonStepNumber><CollapsibleSummaryButtonStepTitle>{stepTitle}</CollapsibleSummaryButtonStepTitle><CollapsibleSummaryButtonStepValue>{stepValue}</CollapsibleSummaryButtonStepValue></CollapsibleSummaryButton></CollapsibleSummary><CollapsibleContent>{children}</CollapsibleContent></Collapsible>
Different text
Using the Collapsible
component (not one of the convenience components), you can set a Collapsible to have different summary text depending on whether it is open or closed.
<Collapsible><CollapsibleSummary><CollapsibleSummaryButton><CollapsibleSummaryTextOpen>Summary text when open</CollapsibleSummaryTextOpen><CollapsibleSummaryTextClosed>Summary text when closed</CollapsibleSummaryTextClosed></CollapsibleSummaryButton></CollapsibleSummary><CollapsibleContent>Content</CollapsibleContent></Collapsible>
Rich summary
Using the Collapsible
component (not one of the convenience components) with the "rich" option allows you to customize the summary typography by putting typographic styles onto sub-elements inside the summary. Those sub-elements will be arranged in a single horizontal line, aligned to the left.
There is an additional option for "rich" summaries that will cause the last sub-element to be aligned to the right instead.
<><Collapsible><CollapsibleSummary rich><CollapsibleSummaryButton><Typography textColor="holiday" textSize={3}>Element 1</Typography><Typography textColor="dark-grey">Element 2</Typography><Typography weight="bold">Element 3</Typography></CollapsibleSummaryButton></CollapsibleSummary><CollapsibleContent>Content of a collapsible with a "rich" summary</CollapsibleContent></Collapsible><Collapsible><CollapsibleSummary rich richLastAlign="right"><CollapsibleSummaryButton><Typography textColor="holiday" textSize={3}>Element 1</Typography><Typography textColor="dark-grey">Element 2</Typography><Typography weight="bold">Element 3</Typography></CollapsibleSummaryButton></CollapsibleSummary><CollapsibleContent>Content of a collapsible with a "rich" summary that is aligning its lastelement to the right</CollapsibleContent></Collapsible></>
Components
CollapsibleSummary
Prop | Type | Default | Description |
---|---|---|---|
rich | boolean | Whether or not the summary is a "rich" summary | |
richLastAlign | string | The alignment for the last sub-element of a "rich" summary |
All other props are forwarded to the element specified in thecomponent
prop(default: <div/>
)
CollapsibleSummaryButtonStepNumber
CollapsibleSummaryButtonStepNumber
has no props of its own
All props are forwarded to the element specified in thecomponent
prop(default: <div/>
)
CollapsibleSummaryButtonStepTitle
CollapsibleSummaryButtonStepTitle
has no props of its own
All props are forwarded to the element specified in thecomponent
prop(default: <div/>
)
Guidelines
See the Accordion page for guidelines for Collapsibles.