Accordion
A vertically stacked set of expandable panels, built with Polaris Card, Box and Collapsible.
Preview
Code
Example.jsx
import { useState } from 'react';
import { Card, Box, InlineStack, BlockStack, Text, Collapsible, Icon, UnstyledButton } from '@shopify/polaris';
import { ChevronUpIcon, ChevronDownIcon } from '@shopify/polaris-icons';
const ACCORDION_ITEMS = [
{
id: 0,
title: 'How do I install the app?',
content:
'Open the Shopify App Store, search for the app, and click Add app. Follow the prompts to grant the required permissions.',
},
{
id: 1,
title: 'Is there a free plan?',
content:
'Yes. The Starter plan is free forever and includes the core features. You can upgrade at any time from the billing page.',
},
{
id: 2,
title: 'How do I contact support?',
content:
'Use the in-app chat, or email support@example.com. We typically reply within a few hours on business days.',
},
];
export const Example = () => {
const [expanded, setExpanded] = useState(0);
return (
<Card padding="0">
<BlockStack>
{ACCORDION_ITEMS.map(({ id, title, content }, index) => {
const isExpanded = expanded === id;
const isLast = index === ACCORDION_ITEMS.length - 1;
return (
<Box
key={id}
borderBlockEndWidth={isLast ? '0' : '025'}
borderColor="border"
background={isExpanded ? 'bg-surface-secondary' : 'bg-surface'}
>
<UnstyledButton
onClick={() => setExpanded((prev) => (prev === id ? null : id))}
ariaExpanded={isExpanded}
ariaControls={`accordion-${id}`}
style={{
width: '100%',
appearance: 'none',
border: 'none',
background: 'none',
padding: 0,
font: 'inherit',
color: 'inherit',
textAlign: 'left',
cursor: 'pointer',
}}
>
<Box paddingBlock="300" paddingInline="400">
<InlineStack align="space-between" blockAlign="center" gap="200" wrap={false}>
<Text variant="headingMd" as="p">
{title}
</Text>
<InlineStack>
<Icon source={isExpanded ? ChevronUpIcon : ChevronDownIcon} tone="subdued" />
</InlineStack>
</InlineStack>
</Box>
</UnstyledButton>
<Collapsible
open={isExpanded}
id={`accordion-${id}`}
transition={{ duration: '200ms', timingFunction: 'ease-in-out' }}
>
<Box paddingBlockEnd="400" paddingInline="400">
<Text as="p" tone="subdued">
{content}
</Text>
</Box>
</Collapsible>
</Box>
);
})}
</BlockStack>
</Card>
);
};