Allow modal close button (or other dismissive actions) to cancel parent actions#19781
Conversation
* Add modal close button parent cancellation Agent-Logs-Url: https://github.com/CamKemBell/filament/sessions/b42b9ac0-2da9-426b-ba8a-1dc091249aaa Co-authored-by: CamKemBell <217516035+CamKemBell@users.noreply.github.com> * Polish modal close button cancellation Agent-Logs-Url: https://github.com/CamKemBell/filament/sessions/b42b9ac0-2da9-426b-ba8a-1dc091249aaa Co-authored-by: CamKemBell <217516035+CamKemBell@users.noreply.github.com> * revert: back to original code * refactor: support for conditional cancellation of parent actions on modal close * refactor: rename modal close button unmount action methods for clarity * refactor: simplify modal close button event handler logic * refactor: simplify modal close button event handler logic --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: CamKemBell <217516035+CamKemBell@users.noreply.github.com> Co-authored-by: Cam Kemshal-Bell <cam@foremind.com.au>
danharrin
left a comment
There was a problem hiding this comment.
There's more than just the close button that closes the modal (Esc key, clicking backdrop, etc) so it feels a bit weird that the API is centered around that. Thoughts?
* Add modal dismissal parent action API Agent-Logs-Url: https://github.com/CamKemBell/filament/sessions/53b18b70-43ab-41f7-9798-48fd987b9baf Co-authored-by: CamKemBell <217516035+CamKemBell@users.noreply.github.com> * Refine modal dismissal API readability Agent-Logs-Url: https://github.com/CamKemBell/filament/sessions/53b18b70-43ab-41f7-9798-48fd987b9baf Co-authored-by: CamKemBell <217516035+CamKemBell@users.noreply.github.com> * Fix modal dismissal flag handling Agent-Logs-Url: https://github.com/CamKemBell/filament/sessions/53b18b70-43ab-41f7-9798-48fd987b9baf Co-authored-by: CamKemBell <217516035+CamKemBell@users.noreply.github.com> * core: remove modalCloseButton method * core: remove deprecate tests * docs: update modal documentation to reflect deprecation of modalCloseButton --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: CamKemBell <217516035+CamKemBell@users.noreply.github.com> Co-authored-by: Cam Kemshal-Bell <cam@foremind.com.au>
…n behavior under a new section
@danharrin - Good point, I have reworked the PR (and updated the description) to move to a chainable method called Happy for any terminology changes if you don't like the Originally was thinking along the lines of |
|
@danharrin - wanted to get some feedback on the rework done on this PR, happy to make further changes if needed to help move it along. |
Description
In workflows with chained nested actions, closing a modal only dismisses the innermost modal, leaving parent modals open with any prefilled form state intact. This means a user intending to abandon a multi-step flow has to close each modal individually, and there is no way to collapse the
entire action stack in one interaction.
This PR adds
modalDismissesParentActions()as a dedicated, first-class method on actions to control what happens when a modal is dismissed. When set, dismissing the modal in any way — close button, Esc key, or clicking the backdrop — will cancel the configured parent actions.API:
->modalDismissesParentActions()— dismiss all parent actions when this modal is closed->modalDismissesParentActions('parentActionName')— dismiss up to a named parent actionDocs:
How it works:
The modal component fires a
modal-closedevent for every dismissal method (close button, Esc, backdrop click). Theaction-modalblade template listens for this event and callsunmountAction()with the configured cancellation behaviour.Visual changes
None.
Functional changes
composer cscommand.