Slide animation

Slide

Usage

import Slide from "@kiwicom/orbit-components/lib/utils/Slide";
<Slide expanded={isExpanded} maxHeight={height}>
{collapsibleContent}
</Slide>;

Props

NameTypeDefaultDescription
transitionDurationstring"fast"Determines the duration of the animation. Can be "slow", "normal" or "fast".
childrenReact.NodeThe expandable content that should be animated.
maxHeightnumber \| nullThe maximum height the animation should take. Usually it is the height of the container.
expandedbooleanfalseDetermines if the content is expanded or not. When changed to true, the animation occurs.
idstringSets the id for the wrapper component responsible for the animation.
ariaLabelledBystringSets the ariaLabelledBy for the wrapper component responsible for the animation.
stopClickPropagationbooleantruePrevents click events inside the component from propagating to parent elements.

Accessibility

Automatic Accessibility Features

  • aria-hidden: Automatically set to true when the content is collapsed and false when expanded
  • aria-labelledby: When provided via the ariaLabelledBy prop, associates the collapsible content with its label element

Best Practices

  1. The control that toggles the expanded state is keyboard focusable and has the corresponding aria-expanded attribute
  2. The control has appropriate aria-controls attribute pointing to the Slide component’s id
  3. If the control is an icon or icon button, it should have an accessible name via aria-label

Example with Accessibility Features

import Slide from "@kiwicom/orbit-components/lib/utils/Slide";
import Button from "@kiwicom/orbit-components/lib/Button";
import Heading from "@kiwicom/orbit-components/lib/Heading";
import Text from "@kiwicom/orbit-components/lib/Text";
import ChevronDown from "@kiwicom/orbit-components/lib/icons/ChevronDown";
import ChevronUp from "@kiwicom/orbit-components/lib/icons/ChevronUp";
const CollapsibleSection = () => {
const [expanded, setExpanded] = React.useState(false);
const toggleExpanded = () => setExpanded(!expanded);
return (
<>
<Button
onClick={toggleExpanded}
iconRight={expanded ? <ChevronUp ariaHidden /> : <ChevronDown ariaHidden />}
aria-expanded={expanded}
aria-controls="details-section"
>
Toggle Details
</Button>
<Slide
expanded={expanded}
maxHeight={200}
id="details-section"
ariaLabelledBy="details-heading"
>
<Heading type="title3" id="details-heading">
Section Details
</Heading>
<Text>This content expands and collapses with animation.</Text>
</Slide>
</>
);
};

Click Propagation