Disclosures ​

The disclosure component provides a set of classes to show and hide content with a button.

Disclosures implement the spec found in the ARIA Authoring Practices Guide.

Base classes ​

Use .disclosure for the panel and .disclosure-content for the wrapper around its contents. Give the panel a unique id and use that ID as the .disclosure-toggle button's data-graupl-disclosure-target.

Once initialized, click the button or press Enter or Space while it has focus to expand or collapse the panel.

Initialization ​

Run the disclosure generator after the markup is in the DOM.

js
import generateDisclosures from "@graupl/core/disclosure/generator";

generateDisclosures();

During initialization, Disclosure sets the button's aria-controls to the panel's ID.

To start expanded, set aria-expanded="true" on the button and add .show to the panel. To start collapsed, set aria-expanded="false" and add .hide. Add inert to the collapsed panel's .disclosure-content so its contents stay out of the tab order before initialization. Disclosure updates the button state and removes inert when the panel opens.

Custom Properties ​

The following custom properties can be used to customize the disclosure component:

PropertyDescriptionDefault Value
--graupl-disclosure-colorText color of the disclosure.var(--graupl-color)
--graupl-disclosure-backgroundBackground of the disclosure.var(--graupl-background)
--graupl-disclosure-content-border-colorBorder color of the disclosure content.var(--graupl-border-color)
--graupl-disclosure-content-padding-xHorizontal padding of the disclosure content.var(--graupl-spacer-5)
--graupl-disclosure-content-padding-yVertical padding of the disclosure content.var(--graupl-spacer-5)
--graupl-disclosure-content-paddingPadding of the disclosure content.var(--graupl-disclosure-content-padding-y) var(--graupl-disclosure-content-padding-x)
--graupl-disclosure-show-displayDisplay of the expanded disclosure.flex
--graupl-disclosure-hide-displayDisplay of the collapsed disclosure.flex
--graupl-disclosure-transitioning-displayDisplay of the transitioning disclosure.flex
--graupl-disclosure-displayDisplay of the disclosure.flex
--graupl-disclosure-show-block-sizeBlock size of the expanded disclosure.auto
--graupl-disclosure-hide-block-sizeBlock size of the collapsed disclosure.0
--graupl-disclosure-transitioning-block-sizeBlock size of the transitioning disclosure.0
--graupl-disclosure-block-sizeBlock size of the disclosure.0
--graupl-disclosure-show-opacityOpacity of the expanded disclosure.1
--graupl-disclosure-hide-opacityOpacity of the collapsed disclosure.0
--graupl-disclosure-transitioning-opacityOpacity of the transitioning disclosure.0
--graupl-disclosure-opacityOpacity of the disclosure.var(--graupl-disclosure-hide-opacity)
--graupl-disclosure-transition-durationTransition duration of the disclosure.var(--graupl-transition-duration-fast)
--graupl-disclosure-transition-timing-functionTransition timing function of the disclosure.var(--graupl-transition-timing-function)
--graupl-disclosure-transitionTransition of the disclosure.opacity var(--graupl-disclosure-transition-duration) var(--graupl-disclosure-transition-timing-function), block-size var(--graupl-disclosure-transition-duration) var(--graupl-disclosure-transition-timing-function)
--graupl-disclosure-transition-reduced-motionTransition of the disclosure when reduced motion is requested.opacity var(--graupl-disclosure-transition-duration) var(--graupl-disclosure-transition-timing-function)
--graupl-disclosure-content-border-top-widthBorder top width of the disclosure content.var(--graupl-border-top-width)
--graupl-disclosure-content-border-right-widthBorder right width of the disclosure content.var(--graupl-border-right-width)
--graupl-disclosure-content-border-bottom-widthBorder bottom width of the disclosure content.var(--graupl-border-bottom-width)
--graupl-disclosure-content-border-left-widthBorder left width of the disclosure content.var(--graupl-border-left-width)
--graupl-disclosure-content-border-widthBorder width of the disclosure content.var(--graupl-disclosure-content-border-top-width) var(--graupl-disclosure-content-border-right-width) var(--graupl-disclosure-content-border-bottom-width) var(--graupl-disclosure-content-border-left-width)
--graupl-disclosure-content-border-top-styleBorder top style of the disclosure content.var(--graupl-border-top-style)
--graupl-disclosure-content-border-right-styleBorder right style of the disclosure content.var(--graupl-border-right-style)
--graupl-disclosure-content-border-bottom-styleBorder bottom style of the disclosure content.var(--graupl-border-bottom-style)
--graupl-disclosure-content-border-left-styleBorder left style of the disclosure content.var(--graupl-border-left-style)
--graupl-disclosure-content-border-styleBorder style of the disclosure content.var(--graupl-disclosure-content-border-top-style) var(--graupl-disclosure-content-border-right-style) var(--graupl-disclosure-content-border-bottom-style) var(--graupl-disclosure-content-border-left-style)
--graupl-disclosure-content-border-top-left-radiusBorder top left radius of the disclosure content.var(--graupl-border-top-left-radius)
--graupl-disclosure-content-border-top-right-radiusBorder top right radius of the disclosure content.var(--graupl-border-top-right-radius)
--graupl-disclosure-content-border-bottom-right-radiusBorder bottom right radius of the disclosure content.var(--graupl-border-bottom-right-radius)
--graupl-disclosure-content-border-bottom-left-radiusBorder bottom left radius of the disclosure content.var(--graupl-border-bottom-left-radius)
--graupl-disclosure-content-border-radiusBorder radius of the disclosure content.var(--graupl-disclosure-content-border-top-left-radius) var(--graupl-disclosure-content-border-top-right-radius) var(--graupl-disclosure-content-border-bottom-right-radius) var(--graupl-disclosure-content-border-bottom-left-radius)
--graupl-disclosure-toggle-transformTransform of the disclosure toggle.rotate(0deg)
--graupl-disclosure-toggle-open-transformExpanded indicator transform of the disclosure toggle.rotate(-180deg)
--graupl-disclosure-toggle-contentIndicator content of the disclosure toggle.'↓'
--graupl-disclosure-toggle-transitionTransition of the disclosure toggle.transform var(--graupl-transition-duration-fast) var(--graupl-transition-timing-function)
--graupl-disclosure-toggle-transition-reduced-motionTransition of the disclosure toggle when reduced motion is requested.none

Sass variables ​

The following Sass variables can be used to customize the generation of the disclosure component:

VariableDescriptionDefault Value
$selector-baseThe selector base for the component."."
$modifier-selector-baseThe selector base for component modifiers."."
$disclosure-selector-baseSelector base for the disclosure."."
$disclosure-selectorSelector for the disclosure."disclosure"
$disclosure-content-selector-baseSelector base for the disclosure content."."
$disclosure-content-selectorSelector for the disclosure content."disclosure-content"
$disclosure-toggle-selector-baseSelector base for the disclosure toggle."."
$disclosure-toggle-selectorSelector for the disclosure toggle."disclosure-toggle"
$disclosure-open-selector-baseSelector base for the expanded disclosure."."
$disclosure-open-selectorSelector for the expanded disclosure."show"
$disclosure-closed-selector-baseSelector base for the collapsed disclosure."."
$disclosure-closed-selectorSelector for the collapsed disclosure."hide"
$disclosure-transitioning-selector-baseSelector base for the transitioning disclosure."."
$disclosure-transitioning-selectorSelector for the transitioning disclosure."transitioning"
$disclosure-show-displayDisplay of the expanded disclosure.flex
$disclosure-hide-displayDisplay of the collapsed disclosure.flex
$disclosure-transitioning-displayDisplay of the transitioning disclosure.flex
$disclosure-show-block-sizeBlock size of the expanded disclosure.auto
$disclosure-hide-block-sizeBlock size of the collapsed disclosure.0
$disclosure-transitioning-block-sizeBlock size of the transitioning disclosure.0
$disclosure-show-opacityOpacity of the expanded disclosure.1
$disclosure-hide-opacityOpacity of the collapsed disclosure.0
$disclosure-transitioning-opacityOpacity of the transitioning disclosure.0
$disclosure-toggle-contentIndicator content of the disclosure toggle."'↓'"
$disclosure-toggle-transformTransform of the disclosure toggle.rotate(0deg)
$disclosure-toggle-open-transformExpanded indicator transform of the disclosure toggle.rotate(-180deg)