Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Edit" button to Zoom Out mode toolbar #64571

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import clsx from 'clsx';
/**
* WordPress dependencies
*/
import { dragHandle, trash } from '@wordpress/icons';
import { dragHandle, trash, edit } from '@wordpress/icons';
import { Button, ToolbarButton } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { store as blocksStore } from '@wordpress/blocks';
Expand Down Expand Up @@ -77,7 +77,8 @@ export default function ZoomOutToolbar( { clientId, rootClientId } ) {
canMove,
} = selected;

const { removeBlock } = useDispatch( blockEditorStore );
const { removeBlock, __unstableSetEditorMode } =
useDispatch( blockEditorStore );

const classNames = clsx( 'zoom-out-toolbar', {
'is-block-moving-mode': !! blockMovingMode,
Expand Down Expand Up @@ -124,6 +125,18 @@ export default function ZoomOutToolbar( { clientId, rootClientId } ) {
{ canMove && canRemove && (
<Shuffle clientId={ clientId } as={ ToolbarButton } />
) }

{ ! isBlockTemplatePart && (
<ToolbarButton
className="zoom-out-toolbar-button"
icon={ edit }
label={ __( 'Edit' ) }
onClick={ () => {
__unstableSetEditorMode( 'edit' );
Copy link
Contributor

Choose a reason for hiding this comment

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

This will cause a focus loss as we are not moving focus after the click and the toolbar disappears. Focus should be placed on the selected block. I believe if we send focus to the canvas it will focus the selected block for us. I can look into that today. If it isn't solvable quickly, we may need to revert this as to not introduce a known focus loss.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great spot. Strange as I thought that was happening when I tested it. Maybe there's an edge case I missed.

Ping me for a review on your PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

It does visually look like focus is moved. It's just bailing to the body of the frame since it doesn't know where to go, and your next Tab press moves focus into the canvas, which is the right spot. So, it's an easy one to miss.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ready for review, @getdave! #64725

} }
/>
) }

{ canRemove && ! isBlockTemplatePart && (
<ToolbarButton
className="zoom-out-toolbar-button"
Expand Down
Loading