Repository navigation
[6.x] Confirm image editor discards in a CP dialog instead of window.confirm() - #20466
Open
brandonkelly wants to merge 2 commits into
Open
brandonkelly wants to merge 2 commits into
brandonkelly wants to merge 2 commits into
Conversation
Closing the image editor with changes, or resetting it to the original, asked with the browser's native confirm(), which blocks the page and can't be themed. Both now ask in a craft-dialog with Cancel focused. The confirmation sits beside the editor's dialog, since craft-dialog's lifecycle events bubble, and openImageEditorDialog() only tears its host down once the editor itself has closed. Amp-Thread-ID: https://ampcode.com/threads/T-01a1b7ff-c89a-7546-b6a9-cdb8ba41cc70 Co-authored-by: Amp <amp@ampcode.com>
[ci skip] Amp-Thread-ID: https://ampcode.com/threads/T-01a1b7ff-c89a-7546-b6a9-cdb8ba41cc70 Co-authored-by: Amp <amp@ampcode.com>
📚 Storybook previews@craftcms/ui — open Storybook No changed components detected in this Storybook. resources/js — open Storybook No changed components detected in this Storybook. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closing the image editor after a change, or clicking “Reset to original”, asked with the browser’s native
window.confirm(). That blocks the page (and freezes browser automation), can’t be themed, and doesn’t match the rest of the control panel. Both now ask in acraft-dialog, the way other in-page CP confirmations do (e.g.WorkflowEditLock.vue): a label, the existing message, a focused Cancel, and a danger action.onBeforeHide(event) // close button, Escape, backdrop if editor.isDirty event.preventDefault() - if window.confirm(…) → close + askToConfirm('close') // opens <craft-dialog> “Discard changes” onConfirmationHidden() // the confirmation's craft-after-hide + if confirmed + 'close' → opened = false // focus has already gone back to the editor, + // so the editor's own return still works + 'reset' → editor.reset(), then focus the selected tab + // the Reset button disables itself after a resetcraft-dialog’s lifecycle events bubble, and the editor listens forcraft-after-show/craft-hideon its own dialog.openImageEditorDialog()tore its host down on the firstcraft-after-hideinside it. It now only tears down once the editor itself is closed, so canceling the confirmation doesn’t unmount the editor.::part()padding overrides now target its own dialog, so they don’t strip the confirmation’s padding.Evidence
New
open-image-editor-dialog.browser.test.tsopens the editor throughopenImageEditorDialog()with an edit pending, then:expected "vi.fn()" to not be called at all, but actually been called 1 timeswith"Any changes will be lost if you close the image editor."expected [] to deeply equal [ 'Edit Image' ]. Canceling unmounted the editor.Checked by hand in the workbench (Chromium): from the asset edit page and from the Assets index “Edit Image” action, the confirmation opens with focus on Cancel. Tab stays inside it. Escape or Cancel returns focus to the control that asked (the editor’s Close button, or Reset). “Discard changes” closes the editor and returns focus to the index’s Actions button. “Reset to original” resets and focuses the selected tab. Closing an unchanged editor doesn’t ask. Screenshots are in the Amp thread; this environment can’t upload images to GitHub.
vp lint,stylelint,vue-tsc, and the image editor unit tests pass. Incomposer ci, pint, rector, phpstan, and the core tests pass. The adapter suite had 3 unrelated failures (ConfigCompatibilityTest,LegacyMarkdownTestdeprecation-log counts). Those tests pass when run alone, and this PR changes no PHP.Not in this PR: about 35 other
confirm()calls across the CP (slideout andcp-modaldirty checks, delete buttons,@craftcms/uiactions, legacy modules). They use a synchronous boolean return, so replacing them needs a shared promise-based confirmation helper. That’s a separate design decision.