Skip to content

useRetained

Keeps the last non-null value while a dialog animates closed.

For a dialog, sheet or popover that shows whichever record is selected, where closing sets the selection to null. Without it the content empties the moment the exit starts. useRetained(selected) gives open for the overlay, value (the selection, or the last one while the overlay leaves) to render, and onOpenChangeComplete to pass to the overlay so the kept copy is dropped once the exit has finished.

A dialog that keeps its content

  • INV-1042
  • INV-1041
  • INV-1040

Installation

npx shadcn@latest add @khaeli/use-retained

Installs with

Nothing else. This item needs no other Registry item and no npm package.

Keyboard

Esc
Closes the dialog. Its title and text stay as they were until it has left.

Accessible name

  • Take the overlay's title from value, not from the selection, so the dialog keeps its name while it closes.

Registry JSON

The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/use-retained.json