---
title: Expandable Panel
description: Photo strips that open wide on hover, focus or tap.
category: Layout
tier: free
url: https://ui.dimaac.com/components/expandable-panel
registry: https://ui.dimaac.com/r/expandable-panel.json
---

# Expandable Panel

An accordion gallery. One photo strip is wide open and the others are slim; hover, focus or tap another and the room moves over to it, with a gentle zoom, a fading shade and a title that slides up. Every strip is a real button with aria-expanded, arrow keys walk along them, and on narrow boxes the strips stack and open downwards instead of overflowing. GSAP tweens flex-grow rather than width, so the layout never jumps, and the movement is skipped for visitors who prefer reduced motion. Ported from the first DiMaac UI, which used a plain CSS width transition on clickable divs.

## Install

With the shadcn CLI:

```bash
npx shadcn@latest add https://ui.dimaac.com/r/expandable-panel.json
pnpm dlx shadcn@latest add https://ui.dimaac.com/r/expandable-panel.json
bunx --bun shadcn@latest add https://ui.dimaac.com/r/expandable-panel.json
```

With the `@dimaac` namespace in components.json: `npx shadcn@latest add @dimaac/expandable-panel`

Dependencies:

```bash
pnpm add gsap @gsap/react
npm install gsap @gsap/react
```

By hand:

1. Install the packages it uses: gsap, @gsap/react.
2. Copy the component file below into components/dimaac/expandable-panel.tsx.
3. It's styled with Tailwind v4 classes. If that folder sits outside the places Tailwind scans, add it with @source in your CSS.
4. Import it with import { ExpandablePanel } from "@/components/dimaac/expandable-panel". Give its parent a size: it fills it.

## Usage

```tsx
import { ExpandablePanel } from "@/components/dimaac/expandable-panel";

<ExpandablePanel panels={panels} />
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `panels` (required) | `ExpandablePanelItem[]` | - | The strips, in order. Four to eight look best. |
| `trigger` | `"hover" \| "click"` | `"hover"` | What opens a strip: "hover" (mouse), or "click". Tap and keyboard focus always open one. |
| `defaultActive` | `number` | `0` | Which strip starts open. -1 starts with all of them closed. |
| `resetOnLeave` | `boolean` | `false` | Go back to the first choice when the pointer leaves the whole row. |
| `expandedRatio` | `number` | `6` | How much wider the open strip is than a closed one (1 is the same width). |
| `gap` | `number` | `12` | Space between the strips, in pixels. |
| `radius` | `number` | `24` | Corner radius of each strip, in pixels. |
| `duration` | `number` | `0.9` | How long the strips take to change size, in seconds. |
| `ease` | `string` | `"expo.out"` | The GSAP ease of the change, e.g. "power3.inOut" or "expo.out". |
| `orientation` | `"auto" \| "horizontal" \| "vertical"` | `"auto"` | "auto" stacks the strips when the box is narrower than 672px. |
| `onChange` | `(index: number) => void` | - | Called with the new strip's index whenever the open one changes. |
| `className` | `string` | `""` | Extra classes for the outer box. Give it a size (it fills it). |
| `panelClassName` | `string` | `""` | Extra classes for each strip. |

## Credits

- Mossy forest: PZF, Lummi (https://www.lummi.ai/photo/mossy-forest-scene-o4b8t), Lummi License
- Yellow planes: rena, Lummi (https://www.lummi.ai/photo/modern-architectural-design-aozka), Lummi License
- Coastline: Cayetano Gros, Lummi (https://www.lummi.ai/photo/dramatic-coastline-aerial-view-jml-7), Lummi License
- Organic forms: Dona Mara, Lummi (https://www.lummi.ai/photo/abstract-sculptural-objects-flp-3), Lummi License
- Desert wanderer: Beth Design Studio, Lummi (https://www.lummi.ai/photo/desert-wanderer-9puhu), Lummi License
- Pastel rooftop: Viri Gutiérrez, Lummi (https://www.lummi.ai/photo/contemplative-silhouette-against-modern-minimalist-architecture-1-haa), Lummi License
- Misty hills: SHIHO, Lummi (https://www.lummi.ai/photo/lush-green-hills-mdvvk), Lummi License

## Source

### expandable-panel.tsx → `components/dimaac/expandable-panel.tsx`

```tsx
"use client";

import { useRef, useState, type KeyboardEvent } from "react";
import { gsap } from "gsap";
import { useGSAP } from "@gsap/react";

// An accordion of photos. One strip is wide open, the rest are slim; hover, focus or tap another
// and the room moves over to it. Each strip is a real button, so the keyboard works too.
// GSAP tweens flex-grow (not width), so the browser shares the space for us and every strip
// stays exactly as tall as the box. On narrow boxes the strips stack and open downwards.

export type ExpandablePanelItem = {
  /** The photo's address. */
  image: string;
  /** Describes the photo for screen readers. */
  alt: string;
  /** The label shown on the open strip, and the accessible name of the button. */
  title: string;
  /** A small line under the title, optional. */
  caption?: string;
};

export type ExpandablePanelProps = {
  /** The strips, in order. Four to eight look best. */
  panels: ExpandablePanelItem[];
  /** What opens a strip: "hover" (mouse), or "click". Tap and keyboard focus always open one. */
  trigger?: "hover" | "click";
  /** Which strip starts open. -1 starts with all of them closed. */
  defaultActive?: number;
  /** Go back to the first choice when the pointer leaves the whole row. */
  resetOnLeave?: boolean;
  /** How much wider the open strip is than a closed one (1 is the same width). */
  expandedRatio?: number;
  /** Space between the strips, in pixels. */
  gap?: number;
  /** Corner radius of each strip, in pixels. */
  radius?: number;
  /** How long the strips take to change size, in seconds. */
  duration?: number;
  /** The GSAP ease of the change, e.g. "power3.inOut" or "expo.out". */
  ease?: string;
  /** "auto" stacks the strips when the box is narrower than 672px. */
  orientation?: "auto" | "horizontal" | "vertical";
  /** Called with the new strip's index whenever the open one changes. */
  onChange?: (index: number) => void;
  /** Extra classes for the outer box. Give it a size (it fills it). */
  className?: string;
  /** Extra classes for each strip. */
  panelClassName?: string;
};

export function ExpandablePanel({
  panels,
  trigger = "hover",
  defaultActive = 0,
  resetOnLeave = false,
  expandedRatio = 6,
  gap = 12,
  radius = 24,
  duration = 0.9,
  ease = "expo.out",
  orientation = "auto",
  onChange,
  className = "",
  panelClassName = "",
}: ExpandablePanelProps) {
  const listRef = useRef<HTMLDivElement>(null);
  const buttonRefs = useRef<(HTMLButtonElement | null)[]>([]);
  const [active, setActive] = useState(defaultActive);
  // The strips are drawn at their starting size by React; after that only GSAP changes them
  const startActive = useRef(defaultActive);
  const started = useRef(false);

  // When the defaultActive prop changes on a live strip (the playground does this), follow it
  const [seenDefault, setSeenDefault] = useState(defaultActive);
  if (seenDefault !== defaultActive) {
    setSeenDefault(defaultActive);
    setActive(defaultActive);
  }

  const open = (index: number) => {
    if (index === active) return;
    setActive(index);
    onChange?.(index);
  };

  useGSAP(
    () => {
      const buttons = buttonRefs.current.slice(0, panels.length).filter((button): button is HTMLButtonElement => button !== null);
      if (buttons.length === 0) return;

      const reduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
      // The first run only places things, so the page doesn't open with an animation nobody asked for
      const time = started.current && !reduced ? duration : 0;
      started.current = true;

      const isOpen = (i: number) => i === active;
      gsap.to(buttons, { flexGrow: (i: number) => (isOpen(i) ? expandedRatio : 1), duration: time, ease, overwrite: "auto" });
      // The photo eases from a slight zoom to rest, and closed strips are dimmed
      gsap.to(buttons.map((b) => b.querySelector("[data-photo]")), { scale: (i: number) => (isOpen(i) ? 1 : 1.12), duration: time * 1.1, ease, overwrite: "auto" });
      gsap.to(buttons.map((b) => b.querySelector("[data-shade]")), { opacity: (i: number) => (isOpen(i) ? 0 : 0.45), duration: time, ease: "power2.out", overwrite: "auto" });
      // The title slides up into view only on the open strip; on the others it fades out quickly
      const titles = buttons.map((b) => b.querySelector("[data-title]"));
      gsap.to(titles, {
        opacity: (i: number) => (isOpen(i) ? 1 : 0),
        y: (i: number) => (isOpen(i) || reduced ? 0 : 18),
        duration: time * 0.6,
        delay: (i: number) => (isOpen(i) && time > 0 ? 0.12 : 0),
        ease: "power3.out",
        overwrite: "auto",
      });
    },
    { scope: listRef, dependencies: [active, panels.length, expandedRatio, duration, ease] },
  );

  // Arrow keys walk along the strips, and landing on one opens it (focus opens)
  const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
    const keys = ["ArrowRight", "ArrowDown", "ArrowLeft", "ArrowUp", "Home", "End"];
    if (!keys.includes(event.key)) return;
    const current = buttonRefs.current.findIndex((button) => button === document.activeElement);
    if (current === -1) return;
    event.preventDefault();
    const last = panels.length - 1;
    const next = event.key === "Home" ? 0 : event.key === "End" ? last : event.key === "ArrowRight" || event.key === "ArrowDown" ? Math.min(last, current + 1) : Math.max(0, current - 1);
    buttonRefs.current[next]?.focus();
  };

  const direction = orientation === "vertical" ? "flex-col" : orientation === "horizontal" ? "flex-row" : "flex-row @max-2xl:flex-col";

  return (
    <div className={`@container relative h-full w-full ${className}`}>
      <div
        ref={listRef}
        role="group"
        aria-label="Expandable panels"
        onKeyDown={onKeyDown}
        onPointerLeave={() => resetOnLeave && open(defaultActive)}
        className={`flex h-full w-full ${direction}`}
        style={{ gap }}
      >
        {panels.map((panel, index) => (
          <button
            key={`${index}-${panel.image}`}
            ref={(button) => {
              buttonRefs.current[index] = button;
            }}
            type="button"
            aria-expanded={index === active}
            aria-label={panel.title}
            onPointerEnter={(event) => {
              // Touch fires an enter just before the tap, so only a real pointer counts as a hover
              if (trigger === "hover" && event.pointerType !== "touch") open(index);
            }}
            onClick={() => open(index)}
            onFocus={() => open(index)}
            className={`group relative isolate min-h-0 min-w-0 basis-0 cursor-pointer overflow-hidden border-0 bg-transparent p-0 text-left text-white outline-none focus-visible:ring-2 focus-visible:ring-white/90 focus-visible:ring-offset-2 focus-visible:ring-offset-black/60 ${panelClassName}`}
            style={{ flexGrow: index === startActive.current ? expandedRatio : 1, borderRadius: radius, WebkitTapHighlightColor: "transparent" }}
          >
            <img
              data-photo
              src={panel.image}
              alt={panel.alt}
              draggable={false}
              loading="lazy"
              decoding="async"
              className="absolute inset-0 -z-10 block h-full w-full object-cover"
              style={{ transform: index === startActive.current ? "scale(1)" : "scale(1.12)" }}
            />
            {/* Darkens closed strips, and the bottom of every strip so the white text reads */}
            <span aria-hidden className="pointer-events-none absolute inset-0 bg-black" data-shade style={{ opacity: index === startActive.current ? 0 : 0.45 }} />
            <span aria-hidden className="pointer-events-none absolute inset-x-0 bottom-0 h-2/5 bg-gradient-to-t from-black/70 to-transparent" />
            <span aria-hidden className="absolute top-4 left-5 font-mono text-[11px] tracking-[0.14em] opacity-80 @max-2xl:top-3">
              {String(index + 1).padStart(2, "0")}
            </span>
            <span data-title className="pointer-events-none absolute right-5 bottom-5 left-5 block whitespace-nowrap" style={{ opacity: index === startActive.current ? 1 : 0 }}>
              <span className="block text-[clamp(22px,2.6vw,40px)] leading-[1.05] font-medium tracking-[-0.03em]">{panel.title}</span>
              {panel.caption ? <span className="mt-1.5 block text-[13px] opacity-75">{panel.caption}</span> : null}
            </span>
          </button>
        ))}
      </div>
    </div>
  );
}
```

### demo.tsx (the demo on the page, not installed)

```tsx
"use client";

import { ExpandablePanel, type ExpandablePanelItem, type ExpandablePanelProps } from "@/components/dimaac/expandable-panel";

// Seven Lummi photos (Lummi License: free for personal and commercial use)
const panels: ExpandablePanelItem[] = [
  { image: "https://ui.dimaac.com/media/nature/mossy-forest-4x5.jpg", alt: "Moss-covered forest floor with misty trees in the background", title: "Mossy Forest", caption: "Quiet, damp and very green" },
  { image: "https://ui.dimaac.com/media/architecture/yellow-planes-4x5.jpg", alt: "Minimalist yellow and beige walls under a clear blue sky", title: "Yellow Planes", caption: "Clean lines at noon" },
  { image: "https://ui.dimaac.com/media/nature/coastline-aerial-4x5.jpg", alt: "Aerial view of turquoise waves crashing against a sandy beach", title: "Coastline", caption: "Where the water meets the cliffs" },
  { image: "https://ui.dimaac.com/media/art/organic-forms-4x5.jpg", alt: "Abstract sculptural objects with organic and geometric forms in neutral tones", title: "Organic Forms", caption: "Sculpture in sand and gold" },
  { image: "https://ui.dimaac.com/media/nature/desert-wanderer-4x5.jpg", alt: "A person in a flowing garment walks across a desert under a golden sky", title: "Desert Wanderer", caption: "A long walk under a golden sky" },
  { image: "https://ui.dimaac.com/media/architecture/pastel-rooftop-4x5.jpg", alt: "Pastel purple and pink architecture with a solitary figure against a blue sky", title: "Pastel Rooftop", caption: "Pink, purple and a lot of sky" },
  { image: "https://ui.dimaac.com/media/nature/misty-hills-4x5.jpg", alt: "Aerial view of green mountains with misty valleys", title: "Misty Hills", caption: "Morning fog in the valleys" },
];

export default function Demo(props: Partial<ExpandablePanelProps>) {
  return (
    <div className="flex h-full w-full flex-col gap-5 bg-[#f3f0eb] p-4 text-[#1c1917] sm:p-8 dark:bg-[#0f0b0b] dark:text-[#e8ddd4]">
      <p className="shrink-0 text-right font-mono text-[11px] tracking-wide uppercase opacity-60">Hover, tap or tab to open</p>
      <div className="min-h-0 flex-1">
        <ExpandablePanel panels={panels} {...props} />
      </div>
    </div>
  );
}
```

## Agent prompt

```text
Add the Expandable Panel component (<ExpandablePanel />) from DiMaac UI to this project.

Docs: https://ui.dimaac.com/components/expandable-panel
Source and dependencies (shadcn registry JSON): https://ui.dimaac.com/r/expandable-panel.json

Install it with:
npx shadcn@latest add https://ui.dimaac.com/r/expandable-panel.json

Then use it like this:
import { ExpandablePanel } from "@/components/dimaac/expandable-panel";
<ExpandablePanel panels={panels} />

If the shadcn CLI isn't set up here, fetch the registry JSON above, write files[0].content to components/dimaac/expandable-panel.tsx and install gsap, @gsap/react.
It uses Tailwind v4 classes, so make sure Tailwind scans that folder. Give its parent a size: it fills it. Keep light and dark mode working and keep its prefers-reduced-motion fallback.
Full index for agents: https://ui.dimaac.com/llms.txt
```
