Spoiler

Shows the start of a long content and a button to read the rest. The button only appears when the content is taller than maxHeight.

General

Set maxHeight in pixels. The content shows in full when it fits.

Labels

Use showLabel and hideLabel to name the button, and initialOpened to start open.

Release notes

Keep a long text short inside a Card, so the next item stays in view.

APIs

Spoiler.Props

AttributeDescriptionTypeAccepted valuesDefault
maxHeightheight in pixels of the content while collapsednumber-100
showLabeltext of the button while collapsedstring-'Show more'
hideLabeltext of the button while openstring-'Hide'
initialOpenedstarts with the content openboolean-false
...native props, passed to the root elementHTMLAttributes'id', 'className', ...-

Ref

The ref points at the root element.

Accessibility

The button is a native button with aria-expanded and aria-controls pointing at the content, so screen readers announce whether it is open. The collapsed text is still in the page, so screen readers read all of it.

Edit this page on GitHub