Skip to content

[6.x] Make Stack and Modal close buttons respect beforeClose - #15685

Merged
jasonvarga merged 4 commits into
6.xfrom
stack-x-before-close
Oct 20, 2026
Merged

jasonvarga merged 4 commits into
6.xfrom
stack-x-before-close

Conversation

@jasonvarga

@jasonvarga jasonvarga commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Description of the Problem

A Stack's beforeClose callback only ran when closing via Esc or the backdrop. The X button in the header, the floating X, and StackClose called close() directly and skipped it. For example, the Page Editor in a structure tree uses beforeClose to warn about unsaved changes, but clicking its X discarded edits without the prompt.

The inline publish form (editing a related entry from a relationship field) had the same problem with its own X button, which closed without checking for unsaved changes.

Modals had the same problem with ModalClose.

What this PR Does

The header X, floating X and StackClose now go through runCloseCallback, the same path Esc and the backdrop use. If beforeClose returns false, the Stack stays open. Calling close() programmatically (e.g. after saving) and the close slot prop still close unconditionally.

The inline publish form's X now uses its existing confirmClose, so it shows the unsaved-changes prompt.

ModalClose now goes through runCloseCallback too. It checks beforeClose but not dismissible, so a Cancel button in a non-dismissible modal still works. Dismissing a modal (Esc or clicking outside) no longer closes it twice, which emitted update:open twice. The dismissible prop description now mentions that it covers Esc as well as clicking outside.

Stacks and Modals without a beforeClose behave the same as before, since it defaults to () => true.

jasonvarga and others added 3 commits October 20, 2026 14:11
The header X, floating X, and StackClose called close() directly, so a beforeClose callback only ran for Esc and backdrop clicks. They now go through runCloseCallback. Programmatic close() is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ts X

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ModalClose called close() directly, skipping the beforeClose callback. It now goes through runCloseCallback, so it still works when the modal isn't dismissible. Also corrects the dismissible prop description to mention Esc.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jasonvarga jasonvarga changed the title [6.x] Make Stack close buttons respect beforeClose [6.x] Make Stack and Modal close buttons respect beforeClose Oct 20, 2026
dismiss() called close() after runCloseCallback had already closed the modal, which emitted update:open twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jasonvarga
jasonvarga merged commit 47ef319 into 6.x Oct 20, 2026
64 of 65 checks passed
@jasonvarga
jasonvarga deleted the stack-x-before-close branch October 20, 2026 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant