Skip to content

Allow modal close button (or other dismissive actions) to cancel parent actions#19781

Merged
danharrin merged 19 commits into
filamentphp:4.xfrom
CamKemBell:add-modal-close-button
Jul 8, 2026
Merged

Allow modal close button (or other dismissive actions) to cancel parent actions#19781
danharrin merged 19 commits into
filamentphp:4.xfrom
CamKemBell:add-modal-close-button

Conversation

@CamKemBell

@CamKemBell CamKemBell commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

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 action

Docs:

  • new section under the modal docs to explain the functionality.

How it works:
The modal component fires a modal-closed event for every dismissal method (close button, Esc, backdrop click). The action-modal blade template listens for this event and calls unmountAction() with the configured cancellation behaviour.

// Cancel all parent actions when a modal is dismissed via any method                                                                                                                                                                                                                                                           
Action::make('confirmCreation')
    ->requiresConfirmation()
    ->modalCloseButton()
    ->modalDismissesParentActions();

// Cancel back to a specific named parent                                                                                                                                                                                                                                                                       
Action::make('editPostMetadata')
    ->requiresConfirmation()                                                                                                                                                                                                                                                                                    
    ->modalDismissesParentActions(cancelParentActions: 'createPost')

Visual changes

None.

Functional changes

  • Code style has been fixed by running the composer cs command.
  • Changes have been tested to not break existing functionality.
  • Documentation is up-to-date.

Copilot AI and others added 2 commits April 28, 2026 13:51
* 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>
@CamKemBell CamKemBell changed the title Add modal close button Allow modal close button to cancel parent actions Apr 28, 2026
@github-project-automation github-project-automation Bot moved this to Todo in Roadmap Apr 28, 2026
@danharrin danharrin added enhancement New feature or request pending review labels Apr 28, 2026
@danharrin danharrin added this to the v4 milestone Apr 28, 2026

@danharrin danharrin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@github-project-automation github-project-automation Bot moved this from Todo to In Progress in Roadmap May 2, 2026
Copilot AI and others added 3 commits May 5, 2026 17:52
* 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>
@CamKemBell

CamKemBell commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

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?

@danharrin - Good point, I have reworked the PR (and updated the description) to move to a chainable method called ->modalDismissesParentActions() that will cancel parent actions for any dismissive action such as esc, close button or clicking backdrop.

Happy for any terminology changes if you don't like the dismissed wording, feel free to update it as you see fit, otherwise tell me what you'd like an I can made appropriate changes.

Originally was thinking along the lines of ->closingModalClosesParentActions(to: 'actionName') but happy to go with whatever wording you'd prefer.

@CamKemBell CamKemBell changed the title Allow modal close button to cancel parent actions Allow modal close button (or other dismissive actions) to cancel parent actions May 5, 2026
@CamKemBell CamKemBell requested a review from danharrin May 6, 2026 00:29
@CamKemBell

Copy link
Copy Markdown
Contributor Author

@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.

@danharrin danharrin merged commit 72690a3 into filamentphp:4.x Jul 8, 2026
23 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Roadmap Jul 8, 2026
@CamKemBell CamKemBell deleted the add-modal-close-button branch July 9, 2026 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants