Skip to main content

Disclosure

Disclosure is an optionally controlled component used to put long sections of information under content blocks that users can expand or collapse by pressing an activator. The activator can be specified as children using an action component (Button, Link or Pressable) or a form control (Checkbox or Switch) component. The content blocks can be specified as children inside a structure component (View, InlineLayout, BlockStack, Grid, etc.).

The library automatically applies the WAI-ARIA Accordion pattern to both the activator and the toggled content.

< | undefined>

For uncontrolled disclosure components, the default open state on the initial render.

It's possible to specify a boolean value, a string value, or an array of string values:

  • true will expand all content
  • false will collapse all content
  • string will expand the content with the matching id
  • string[] will expand the content with the matching ids
(open: string[]) => void

Callback fired when the open state of the disclosure changes.

For controlled disclosure components, the open state. The open prop should be used along with onToggle to create a controlled disclosure component.

"none"

Set to 'none' to disable the default transition animation.

Was this section helpful?

Basic Disclosure

import {
reactExtension,
Disclosure,
Button,
View,
} from '@shopify/ui-extensions-react/checkout';

export default reactExtension(
'purchase.checkout.block.render',
() => <Extension />,
);

function Extension() {
return (
<Disclosure>
<Button toggles="one">Toggle</Button>
<View id="one">Content</View>
</Disclosure>
);
}

Preview

  • Disclosures should be initiated by the buyer.

  • Use disclosures to hide content until they are relevant to the buyer.

  • Avoid hiding critical information that buyers need to complete their checkout.

  • Keep content inside disclosures concise.

  • Avoid nesting of disclosures.

  • Keep the activator and the content it toggles in close proximity to each other.

Was this section helpful?

Anchor to example-strategies-for-simplifying-layout-and-aligning-content-using-disclosure-and-inline/block-layout-components.Strategies for simplifying layout and aligning content using Disclosure and Inline/Block Layout components.

Use the Disclosure component to simplify the user experience and reveal interfaces only when the customer requests it. It also demonstrates how a combination of inline and block layout components can improve the readability of information. By employing these strategies, users can easily scan and comprehend the content, making for a better user experience overall.

Was this section helpful?

Strategies for simplifying layout and aligning content using Disclosure and Inline/Block Layout components.

import {
reactExtension,
View,
Image,
Icon,
Pressable,
Disclosure,
InlineLayout,
BlockStack,
Text,
Form,
TextField,
Button,
Divider,
InlineStack,
} from '@shopify/ui-extensions-react/checkout';

export default reactExtension(
'purchase.checkout.block.render',
() => <DisclosureAndAlignment />,
);

export const DisclosureAndAlignment = () => {
const openIds = ['one'];
return (
<View
maxInlineSize={400}
cornerRadius="large"
border="base"
>
<BlockStack spacing="none">
<Disclosure
defaultOpen="one"
onToggle={(open) =>
console.log('onToggle event', open)
}
>
<Pressable toggles="one" padding="base">
<InlineLayout
blockAlignment="center"
spacing="base"
columns={['auto', 'fill', 'auto']}
>
<Icon
source="gift"
appearance="subdued"
/>
Gift message
<Icon
source={
openIds.includes('one')
? 'chevronUp'
: 'chevronDown'
}
appearance="subdued"
/>
</InlineLayout>
</Pressable>
<View
id="one"
padding={[
'none',
'base',
'base',
'base',
]}
>
<Form
onSubmit={() =>
console.log('onSubmit event')
}
>
<BlockStack>
<InlineLayout
columns={['fill', 'fill']}
spacing="base"
>
<TextField
label="From"
name="from0"
id="from0"
/>
<TextField
label="To"
name="to0"
id="to0"
/>
</InlineLayout>
<TextField
label="Message"
name="message0"
id="message0"
/>
<View>
<Button
accessibilityRole="submit"
kind="secondary"
>
Save
</Button>
</View>
</BlockStack>
</Form>
</View>
</Disclosure>
<Divider />
<InlineLayout
blockAlignment="baseline"
spacing="base"
columns={['auto', 'fill', 'auto']}
padding="base"
>
<Icon
source="profile"
appearance="subdued"
/>
<BlockStack spacing="none">
<InlineStack blockAlignment="center">
<Text>Verify with</Text>
<Image source="https://via.placeholder.com/50x15" />
</InlineStack>
<Text
appearance="subdued"
size="small"
>
15% savings for students and
military
</Text>
</BlockStack>
<Pressable to="https://www.shopify.com">
<Icon
source="external"
appearance="subdued"
/>
</Pressable>
</InlineLayout>
</BlockStack>
</View>
);
};

Preview