Spoiler
Hide long sections of content under a spoiler
Source
LLM docs
Docs
Package
Usage
Use Spoiler to hide a long section of content.
Set the maxHeight prop to control the point at which content will be hidden under the spoiler and the show/hide control appears.
If the content height is less than maxHeight, the spoiler will just render children.
hideLabel and showLabel props are required – they are used as the spoiler toggle button label in the corresponding state.

Deserts cover about one third of the land surface of the Earth. They are defined by low rainfall rather than by heat: some of the largest deserts, such as Antarctica and the Gobi, are cold for most of the year. Sand dunes are the most familiar desert landscape, yet they cover only a small part of desert areas. Most deserts are rocky plains, gravel fields and dry mountain ranges. Plants and animals that live there have adapted to save water: cacti store it in their thick stems, and many animals are active only at night when the air is cooler.
Control expanded state
To control the expanded state, use expanded and onExpandedChange props. Note that the
expanded prop does not have any effect on spoiler visuals if the content height
is less than the given maxHeight.
Subscribe to expanded state changes
Use onExpandedChange to subscribe to expanded state changes:
Transition duration
Control the transition duration by setting the transitionDuration prop (transition-duration CSS property in ms).
To disable animations, set transitionDuration={0}:

Deserts cover about one third of the land surface of the Earth. They are defined by low rainfall rather than by heat: some of the largest deserts, such as Antarctica and the Gobi, are cold for most of the year. Sand dunes are the most familiar desert landscape, yet they cover only a small part of desert areas. Most deserts are rocky plains, gravel fields and dry mountain ranges. Plants and animals that live there have adapted to save water: cacti store it in their thick stems, and many animals are active only at night when the air is cooler.
Get control ref
Accessibility
The Spoiler component implements proper ARIA attributes for screen reader support:
- Toggle button has
aria-expandedindicating the expanded/collapsed state - Content region has
role="region"and is associated with the button viaaria-controls - Keyboard support: Space or Enter key toggles the spoiler when the button is focused
Best practices for label text
Provide descriptive labels for showLabel and hideLabel props that clearly indicate the action:
Custom accessibility labels
If your button labels don't clearly describe the action for screen reader users, use the showAriaLabel and hideAriaLabel props to provide custom ARIA labels: