Collapsible

An interactive component which expands/collapses a panel.

import React, { useState } from 'react';
import {
Collapsible,
CollapsibleTrigger,
CollapsibleContent,
Icon,
} from '@minddrop/ui';
const NavItem = ({ children, subItem, ...other }) => (
<div role="button" {...other} style={{ width: 200, height: 28, borderRadius: 3, display: 'flex', alignItems: 'center', marginBottom: 6, backgroundColor: 'var(--bgApp)', paddingLeft: subItem ? 30 : 6, cursor: 'pointer', userSelect: 'none', }} >
{children}
</div>
);
export const CollapsibleDemo = () => {
const [open, setOpen] = useState(false);
return (
<div style={{ display: 'flex', alignItems: 'center', }} >
<Collapsible open={open} onOpenChange={setOpen}>
<CollapsibleTrigger>
<NavItem>
<span>
<Icon name="toggle-filled" color="regular" style={{ transform: open ? 'rotate(90deg)' : 'none', }} />
</span>
Books
</NavItem>
</CollapsibleTrigger>
<CollapsibleContent>
<NavItem subItem>The book of tea</NavItem>
<NavItem subItem>All the tea in China</NavItem>
<NavItem subItem>Tea: A User&apos;s Guide</NavItem>
</CollapsibleContent>
</Collapsible>
</div>
);
};
export default CollapsibleDemo;

Features

  • Full keyboard navigation.
  • Can be controlled or uncontrolled.

Import the component from the @minddrop/ui package.

import { Collapsible } from '@minddrop/ui';
export default () => {
return (
<Collapsible>
<CollapsibleTrigger>
<NavItem />
</CollapsibleTrigger>
<CollapsibleContent>
<SubNavItem />
<SubNavItem />
</CollapsibleContent>
</Collapsible>
);
};

Contains all the parts of a collapsible.

PropTypeDefault
asChildbooleanfalse
defaultOpenbooleanNo default value
openbooleanNo default value
onOpenChangefunctionNo default value
disabledbooleanNo default value

The button that toggles the collapsible.

PropTypeDefault
asChildbooleanfalse

The component that contains the collapsible content.

PropTypeDefault
asChildbooleanfalse
forceMountbooleanNo default value

Use the --radix-collapsible-content-width and/or --radix-collapsible-content-height CSS variables to animate the size of the content when it opens/closes.

@keyframes open {
from {
height: 0;
}
to {
height: var(--radix-collapsible-content-height);
}
}
@keyframes close {
from {
height: var(--radix-collapsible-content-height);
}
to {
height: 0;
}
}

Adheres to the Disclosure WAI-ARIA design pattern.

KeyDescription
SpaceOpens/closes the collapsible.
EnterOpens/closes the collapsible.