Controlled state

Let a parent component coordinate the zoom with the rest of your interface. This photo inspector opens from an asset action and provides its own toolbar while the image is enlarged.

photo-inspector.tsx
Selected assetReady to inspect
ocean-sunset.jpg1920 × 1280 · JPEG
Press Enter or Space to zoom. Click, press Escape, or scroll to close.

Control the zoom

Pass open and onOpenChange={setOpen} to <ImageZoom.Root>.

The parent owns the state. “Inspect photo” calls setOpen(true); “Close preview” calls setOpen(false). The inspection toolbar is rendered into document.body with a portal so it stays above the zoom overlay.

Apply each request from onOpenChange to open. This keeps the parent in sync when the user closes with Escape, the overlay, or scrolling, as well as with your own controls.

The same state props work with <ImageZoom>.

Internal state

Omit open to let the component manage its own state. You can still pass onOpenChange to observe state requests.

Keep the component controlled or uncontrolled throughout its lifetime.