# Animate a Glass Panel Before Unmounting It

React removes a conditional child as soon as state changes. To run QuickLiquid's exit animation, leave the surface mounted until `LiquidGlassRef.animateOut()` resolves. This pattern works for an inline disclosure with a persistent trigger.

## Keep the panel mounted during the exit

```tsx
import { useRef, useState } from 'react';
import { LiquidGlass, type LiquidGlassRef } from 'quick-liquid/react';

export function GlassDetails() {
  const [open, setOpen] = useState(false);
  const closing = useRef(false);
  const trigger = useRef<HTMLButtonElement>(null);
  const glass = useRef<LiquidGlassRef>(null);

  async function toggle() {
    if (closing.current) return;
    if (!open) {
      setOpen(true);
      return;
    }
    closing.current = true;
    try {
      await glass.current?.animateOut();
    } finally {
      trigger.current?.focus();
      setOpen(false);
      closing.current = false;
    }
  }

  return (
    <section>
      <button ref={trigger} type="button" aria-expanded={open} onClick={toggle}>
        Lens details
      </button>
      {open && <LiquidGlass ref={glass} animateIn><p>Thin glass with a soft rim.</p></LiquidGlass>}
    </section>
  );
}
```

The early guard prevents two close requests from running at the same time. The `finally` block also closes the panel if the animation cannot finish normally. A fresh mount runs `animateIn` again. Adjust the layout around the panel so its removal leaves the page in an expected position.

## Keep the interaction in charge of focus

The component above moves focus to the disclosure button before removal. If focus can be elsewhere during the transition, decide whether it should move based on your interaction. For a modal, use a dialog with the appropriate focus handling and use QuickLiquid as its visual treatment. [The accessibility guide](/blog/accessible-liquid-glass/) covers contrast and motion checks to use alongside this pattern.
