Search documentation v0.8.1

Spoiler

Hide content until the user chooses to reveal it

Source ↗️ Report Issue ↗️

Use the Spoiler component to prevent spoilers in content like reviews or discussions or to protect sensitive information. Text wrapped in a Spoiler component is only revealed after a click:

Preview
This text is only visible after click.
How to use Spoilers in Astro
---
import { Spoiler } from 'webcoreui/astro'
---
<Spoiler>This text is only visible after click.</Spoiler>
How to use Spoilers in Svelte
<script>
import { Spoiler } from 'webcoreui/svelte'
</script>
<Spoiler>This text is only visible after click.</Spoiler>
How to use Spoilers in React
import React from 'react'
import { Spoiler } from 'webcoreui/react'
const Component = () => (
<Spoiler>This text is only visible after click.</Spoiler>
)
export default Component

Tooltips

To better indicate the purpose of Spoiler components, you can optionally add a tooltip to the element using the tooltip prop. You can also change the positioning of the tooltip using the tooltipPosition prop:

Spoiler with tooltip
This text is only visible after click.
Bottom tooltip
This text is only visible after click.
<Spoiler tooltip="Click to reveal">This text is only visible after click.</Spoiler>
<Spoiler tooltip="Click to reveal" tooltipPosition="bottom">
This text is only visible after click.
</Spoiler>

Inline vs Block Spoilers

By default, the Spoiler component has its display set to inline to ensure each line is hidden separately. To make the element behave as a single block, you can set the block prop to true:

Default spoiler
This text is only visible after click. Long texts that wrap into multiple lines are hidden separately. To turn the Spoiler component into a single block, use the block prop.
Spoiler set to block
This text is only visible after click. Long texts that wrap into multiple lines are hidden separately. To turn the Spoiler component into a single block, use the block prop.
<Spoiler block={true}>...</Spoiler>

Styles

You can also change the style of the Spoiler component using the color prop:

This text is only visible after click.
<Spoiler color="var(--w-color-warning)">...</Spoiler>

In case you want to use a single color for all of your Spoiler components, its recommended to set the color globally by overriding the following CSS variables:

html body {
--w-spoiler-color: var(--w-color-primary);
}

You can also disable animations by setting the animated prop to false:

Animated
This text is only visible after click.
Animation turned off
This text is only visible after click.
<Spoiler animated={false}>...</Spoiler>
If you need to disable animations globally, you can set the $disableAnimations variable to true in your webcore.config.scss file.

API

type SpoilerProps = {
color?: string
animated?: boolean
block?: boolean
tooltip?: string
tooltipPosition?: 'bottom'
}
PropDefaultPurpose
color var(--w-color-primary) Sets the color of the spoiler.
animated true Sets a fade animation.
block false Sets the style of the spoiler to a block element.
tooltip - Sets a tooltip for the spoiler.
tooltipPosition - Sets the position of the tooltip.

Request improvement for this page