Skip to content

"View XXX" displayed in the snack bar should open in a new tab #59139

@t-hamano

Description

@t-hamano

Description

From Slack: https://wordpress.slack.com/archives/C02RQBWTW/p1708099370819139

The "view preview" that pops up in the bottom left when you save should open in a new tab, like the "Preview in new tab" link does. Having it open same-screen makes no sense.

image

We'll probably need to change the "View site" link in the site editor as well.

image

However, the Snackbar component currently doesn't seem to have a target attribute.

This can be achieved by making the following changes, but I feel that this is not a straightforward approach.

diff --git a/packages/editor/src/store/utils/notice-builder.js b/packages/editor/src/store/utils/notice-builder.js
index 58fc9ca0d7..0027560014 100644
--- a/packages/editor/src/store/utils/notice-builder.js
+++ b/packages/editor/src/store/utils/notice-builder.js
@@ -63,6 +63,10 @@ export function getNotificationArgumentsForSaveSuccess( data ) {
                actions.push( {
                        label: isDraft ? __( 'View Preview' ) : postType.labels.view_item,
                        url: post.link,
+                       onClick: ( event ) => {
+                               window.open( post.link, '_blank' );
+                               event.preventDefault();
+                       },
                } );
        }
        return [

Ideally, I think we would need to add a new target option to the Notice Snackbar component.

Step-by-step reproduction instructions

  • Open the post editor.
  • Make changes and save.
  • Click "View post" that appears at the bottom left.
  • The post should open on the same screen.

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions