Skip to Content

AssetPickerDialog

Select one or multiple existing media asset IDs in a responsive dialog backed by MediaLibrary.

AssetPickerDialog composes MediaLibrary with UI Dialog on wide viewports and UI Drawer on narrow viewports. It stages selection until the caller confirms; cancel and Escape do not change the supplied value.

390 × 844

API

PropTypeRequiredDefault
openbooleanYes—
onOpenChange(open: boolean) => voidYes—
libraryPropsMediaLibraryPropsForPickerYes—
onConfirm(assetId: string) => void or (assetIds: string[]) => voidYes—
multiplebooleanNofalse
valuestring | null or readonly string[]No—
allowedKindsreadonly MediaLibraryAssetKind[]NoAll kinds
initialFolderIdstring | nullNoRoot
title / descriptionstringNo"Choose media" / —
confirmLabel / cancelLabelstringNo"Choose asset" / "Cancel"

Use the discriminated multiple API: a single picker confirms one asset ID, while multiple confirms a list of IDs. libraryProps supplies the same caller-owned assets, folders, query behavior, upload actions, and states as MediaLibrary; selection props are managed by the dialog.

import { AssetPickerDialog } from "@puzzle-ui/pieces";

<AssetPickerDialog
  open={open}
  onOpenChange={setOpen}
  libraryProps={{ assets, folders }}
  allowedKinds={["image"]}
  value={assetId}
  onConfirm={(nextAssetId) => setAssetId(nextAssetId)}
/>;

Responsive behavior and accessibility

On desktop the component uses UI Dialog; on narrow screens it uses UI Drawer. Both reuse the UI overlay's modal focus management, close behavior, and Escape support. The drawer has a labeled heading, scrollable content, and persistent selection actions. Keep an accessible trigger in the calling application so focus can return after closing.

The embedded library remains keyboard-operable and responsive. Selection is constrained to the supplied allowedKinds; confirmation is disabled until an eligible asset is selected. Preview URLs are caller-provided temporary authorized URLs, and selection always returns IDs rather than URLs.

Theme and customization

The dialog uses UI overlay sizing and the drawer uses the public Theme tablet breakpoint. Library layout and controls inherit semantic Theme tokens. Pass the library's error, loading, permissions, and upload actions through libraryProps rather than adding a second picker flow.

TypeScript example

Use multiple as a literal to select the matching callback contract:

<AssetPickerDialog
  open={open}
  onOpenChange={setOpen}
  libraryProps={{ assets, folders }}
  multiple
  value={assetIds}
  onConfirm={(ids) => setAssetIds(ids)}
/>;

API maturity

API maturity: Stable.

See the framework integration guide for client and SSR boundaries.