No standard hooks for document drawer
Describe the Bug
Feature Request: Add onClose callback to useDocumentDrawer for non-save closures
Is your feature request related to a problem? Please describe.
Currently, when using the useDocumentDrawer hook, there doesn't seem to be a straightforward way to trigger a callback function specifically when the drawer is closed without saving (e.g., by clicking the 'X' icon or pressing the Esc key). While there are handlers like onSave and onDelete for data-related actions, there isn't an equivalent for a simple close event.
This makes it difficult to perform cleanup actions, such as clearing temporary initial data, when the user dismisses the drawer without an explicit save or delete action.
Describe the solution you'd like
It would be beneficial to have an onClose prop available on the DocumentDrawer component returned by the useDocumentDrawer hook. This callback would be invoked whenever the drawer is closed, regardless of whether data was saved or not.
Ideally, it would function similarly to how onClose props work in other modal/drawer components:
const [DocumentDrawer, , { openDrawer, closeDrawer }] = useDocumentDrawer({ collectionSlug });
return (
<DocumentDrawer
initialData={{}}
onClose={() => {
// This code should run when the drawer is closed via 'X', Esc, or programmatically
// without a save action.
clearInitData();
}}
/>
);
### Link to the code that reproduces this issue
https://github.com/payloadcms/payload/blob/main/packages/ui/src/elements/DocumentDrawer/index.tsx
### Reproduction Steps
See above
### Which area(s) are affected? (Select all that apply)
area: core
### Environment Info
```text
Payload: 3.39.1