Disclosure API
Import
Section titled “Import”Cimpress UI exports two disclosure-related components:
Disclosure: main component to display a disclosure.DisclosureGroup: container component that groups related disclosures together, providing layout and shared state management.
import { Disclosure, DisclosureGroup } from '@cimpress-ui/react';Controlled/uncontrolled usage
Section titled “Controlled/uncontrolled usage”This component can be used in a controlled or uncontrolled way.
In the controlled way, this component doesn’t maintain its own internal state, and its value is provided by the parent component. Use the controlled way when you need to be able to change the state of this component in other parts of your application.
In the uncontrolled way, this component maintains its own internal state, and can optionally notify the parent component when its internal state changes. Use the uncontrolled way when you don’t need to change the state of this component in other parts of your application.
Single disclosure
Section titled “Single disclosure”import { Disclosure, Stack } from '@cimpress-ui/react';import { useState } from 'react';
export default function Demo() { const [isExpanded, setIsExpanded] = useState(false);
return ( <Stack gap={32}> <Disclosure title="Controlled" isExpanded={isExpanded} onExpandedChange={setIsExpanded}> I am controlled by React state </Disclosure>
<Disclosure title="Uncontrolled collapsed">I am uncontrolled and collapsed by default</Disclosure>
<Disclosure title="Uncontrolled expanded" defaultExpanded> I am uncontrolled and expanded by default </Disclosure> </Stack> );}Disclosure group
Section titled “Disclosure group”Controlled
Uncontrolled
import { Disclosure, DisclosureGroup, type Key, Stack, Text } from '@cimpress-ui/react';import { useState } from 'react';
export default function Demo() { const [expandedKeys, setExpandedKeys] = useState<Set<Key>>(() => new Set(['apple']));
return ( <Stack gap={32}> <Stack gap={16}> <Text as="h2" variant="title-4"> Controlled </Text>
<DisclosureGroup expandedKeys={expandedKeys} onExpandedChange={setExpandedKeys}> <Disclosure id="apple" title="Apple"> My favorite fruit is apple! </Disclosure> <Disclosure id="banana" title="Banana"> My favorite fruit is banana! </Disclosure> <Disclosure id="cherry" title="Cherry"> My favorite fruit is cherry! </Disclosure> </DisclosureGroup> </Stack>
<Stack gap={16}> <Text as="h2" variant="title-4"> Uncontrolled </Text>
<DisclosureGroup defaultExpandedKeys={['apple']}> <Disclosure id="apple" title="Apple"> My favorite fruit is apple! </Disclosure> <Disclosure id="banana" title="Banana"> My favorite fruit is banana! </Disclosure> <Disclosure id="cherry" title="Cherry"> My favorite fruit is cherry! </Disclosure> </DisclosureGroup> </Stack> </Stack> );}Accessibility notes
Section titled “Accessibility notes”Disclosures can be expanded/collapsed by pressing Enter or Space when the disclosure header is focused.
Disclosures use the hidden="until-found" attribute in supported browsers, allowing the disclosure to be automatically expanded when a user’s search term matches the collapsed content.
Disclosure requires a title to remain accessible to assistive technologies. Always provide a non-empty value to the title prop.
Group state management
Section titled “Group state management”Expanded state of disclosures within DisclosureGroup cannot be set individually.
Please use DisclosureGroup’s expandedKeys/defaultExpandedKeys props instead.
// This won't work! :(<DisclosureGroup> <Disclosure id="fruits" title="Fruits"> Apple, banana, cherry </Disclosure> <Disclosure id="vegetables" title="Vegetables" defaultExpanded> Carrot, broccoli, arugula </Disclosure></DisclosureGroup>
// But this will :)<DisclosureGroup defaultExpandedKeys={['vegetables']}> <Disclosure id="fruits" title="Fruits"> Apple, banana, cherry </Disclosure> <Disclosure id="vegetables" title="Vegetables"> Carrot, broccoli, arugula </Disclosure></DisclosureGroup>API reference
Section titled “API reference”Disclosure
Section titled “Disclosure”Displays a collapsible section of content.
- Ref<HTMLDivElement>
-
The
reftype for this component.
DisclosureProps
- ReactNode
children *
Section titled “ children * ” -
The content to display when the disclosure is expanded.
- string
title *
Section titled “ title * ” -
The title that is always visible in the disclosure header.
- Key
-
A unique ID for the disclosure when used within a
DisclosureGroup. - DisclosureVariant
variant
Section titled “ variant ” - Defaults to 'base' .
Determines the visual appearance of the disclosure. If the disclosure is part of a group, this prop has no effect - provide
varianttoDisclosureGroupinstead. - DisclosureSize
- Defaults to 'medium' .
Determines the size of the disclosure. If the disclosure is part of a group, this prop has no effect - provide
sizetoDisclosureGroupinstead. - ReactNode
iconStart
Section titled “ iconStart ” -
An icon displayed before the disclosure title.
Should not be used when size is set to
'small'as icons won't be displayed at this size. - ReactNode
iconEnd
Section titled “ iconEnd ” -
An icon displayed after the disclosure title.
Should not be used when size is set to
'small'as icons won't be displayed at this size. - ReactNode
badge
Section titled “ badge ” -
The badge displayed in the disclosure header.
Should not be used when size is set to
'small'as the badge won't be displayed at this size. - ReactNode
actions
Section titled “ actions ” -
The actions displayed in the disclosure header.
- boolean
data-cim-style-root
Section titled “ data-cim-style-root ” -
Use this attribute to "claim" the component tree for exclusive Cimpress UI usage.
- string
UNSAFE_className
Section titled “ UNSAFE_className ” -
Sets the CSS className for the element. Only use as a last resort. Use style props instead.
See styling guide.
- CSSProperties
UNSAFE_style
Section titled “ UNSAFE_style ” -
Sets the CSS style for the element. Only use as a last resort. Use style props instead.
See styling guide.
- boolean
isDisabled
Section titled “ isDisabled ” -
Whether the disclosure is disabled.
- (isExpanded: boolean) => void
onExpandedChange
Section titled “ onExpandedChange ” -
Handler that is called when the disclosure's expanded state changes.
- boolean
isExpanded
Section titled “ isExpanded ” -
Whether the disclosure is expanded (controlled).
- boolean
defaultExpanded
Section titled “ defaultExpanded ” -
Whether the disclosure is expanded by default (uncontrolled).
StyleProps
- Responsive<Spacing | "auto">
margin
Section titled “ margin ” -
The amount of margin applied to all edges of this component.
- Responsive<Spacing | "auto">
marginX
Section titled “ marginX ” -
The amount of margin applied to the left and right edges of this component. Takes priority over
margin. - Responsive<Spacing | "auto">
marginY
Section titled “ marginY ” -
The amount of margin applied to the top and bottom edges of this component. Takes priority over
margin. - Responsive<Spacing | "auto">
marginTop
Section titled “ marginTop ” -
The amount of margin applied to the top edge of this component. Takes priority over
marginYandmargin. - Responsive<Spacing | "auto">
marginRight
Section titled “ marginRight ” -
The amount of margin applied to the right edge of this component. Takes priority over
marginXandmargin. - Responsive<Spacing | "auto">
marginBottom
Section titled “ marginBottom ” -
The amount of margin applied to the bottom edge of this component. Takes priority over
marginYandmargin. - Responsive<Spacing | "auto">
marginLeft
Section titled “ marginLeft ” -
The amount of margin applied to the left edge of this component. Takes priority over
marginXandmargin.
DisclosureGroup
Section titled “DisclosureGroup”Displays a grouping of related disclosures.
- Ref<HTMLDivElement>
-
The
reftype for this component.
DisclosureGroupProps
- ReactNode
children *
Section titled “ children * ” -
The disclosures to group together.
- DisclosureVariant
variant
Section titled “ variant ” - Defaults to 'base' .
Determines the visual appearance of disclosures within this group.
- DisclosureSize
- Defaults to 'medium' .
Determines the size of disclosures within this group.
- (keys: Set<Key>) => void
onExpandedChange
Section titled “ onExpandedChange ” -
Handler that is called when any disclosure in this group is expanded or collapsed.
- string
-
The element's unique identifier. See MDN.
- boolean
data-cim-style-root
Section titled “ data-cim-style-root ” -
Use this attribute to "claim" the component tree for exclusive Cimpress UI usage.
- string
UNSAFE_className
Section titled “ UNSAFE_className ” -
Sets the CSS className for the element. Only use as a last resort. Use style props instead.
See styling guide.
- CSSProperties
UNSAFE_style
Section titled “ UNSAFE_style ” -
Sets the CSS style for the element. Only use as a last resort. Use style props instead.
See styling guide.
- boolean
allowsMultipleExpanded
Section titled “ allowsMultipleExpanded ” -
Whether multiple items can be expanded at the same time.
- boolean
isDisabled
Section titled “ isDisabled ” -
Whether all items are disabled.
- Iterable<Key, any, any>
expandedKeys
Section titled “ expandedKeys ” -
The currently expanded keys in the group (controlled).
- Iterable<Key, any, any>
defaultExpandedKeys
Section titled “ defaultExpandedKeys ” -
The initial expanded keys in the group (uncontrolled).
StyleProps
- Responsive<Spacing | "auto">
margin
Section titled “ margin ” -
The amount of margin applied to all edges of this component.
- Responsive<Spacing | "auto">
marginX
Section titled “ marginX ” -
The amount of margin applied to the left and right edges of this component. Takes priority over
margin. - Responsive<Spacing | "auto">
marginY
Section titled “ marginY ” -
The amount of margin applied to the top and bottom edges of this component. Takes priority over
margin. - Responsive<Spacing | "auto">
marginTop
Section titled “ marginTop ” -
The amount of margin applied to the top edge of this component. Takes priority over
marginYandmargin. - Responsive<Spacing | "auto">
marginRight
Section titled “ marginRight ” -
The amount of margin applied to the right edge of this component. Takes priority over
marginXandmargin. - Responsive<Spacing | "auto">
marginBottom
Section titled “ marginBottom ” -
The amount of margin applied to the bottom edge of this component. Takes priority over
marginYandmargin. - Responsive<Spacing | "auto">
marginLeft
Section titled “ marginLeft ” -
The amount of margin applied to the left edge of this component. Takes priority over
marginXandmargin.