From 7bd83cff5a64b5a8e272f3d3cd7edc2a0ba6c246 Mon Sep 17 00:00:00 2001 From: Jerry Jones Date: Fri, 14 Jun 2024 11:10:23 -0500 Subject: [PATCH] Only show focus on editor region with focus-visible --- .../block-tools/block-selection-button.js | 8 ++++---- .../block-tools/block-toolbar-breadcrumb.js | 13 +++++++++---- .../src/components/block-tools/index.js | 9 +++++++-- .../src/higher-order/navigate-regions/style.scss | 2 +- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/packages/block-editor/src/components/block-tools/block-selection-button.js b/packages/block-editor/src/components/block-tools/block-selection-button.js index f6c6019d50efee..f96f5678cd5c3a 100644 --- a/packages/block-editor/src/components/block-tools/block-selection-button.js +++ b/packages/block-editor/src/components/block-tools/block-selection-button.js @@ -9,7 +9,7 @@ import clsx from 'clsx'; import { dragHandle, trash } from '@wordpress/icons'; import { Button, Flex, FlexItem, ToolbarButton } from '@wordpress/components'; import { useSelect, useDispatch } from '@wordpress/data'; -import { useEffect, useRef } from '@wordpress/element'; +import { forwardRef, useEffect } from '@wordpress/element'; import { BACKSPACE, DELETE, @@ -48,10 +48,11 @@ import Shuffle from '../block-toolbar/shuffle'; * * @param {string} props Component props. * @param {string} props.clientId Client ID of block. + * @param {Object} ref Reference to the component. * * @return {Component} The component to be rendered. */ -function BlockSelectionButton( { clientId, rootClientId } ) { +function BlockSelectionButton( { clientId, rootClientId }, ref ) { const selected = useSelect( ( select ) => { const { @@ -125,7 +126,6 @@ function BlockSelectionButton( { clientId, rootClientId } ) { canMove, } = selected; const { setNavigationMode, removeBlock } = useDispatch( blockEditorStore ); - const ref = useRef(); // Focus the breadcrumb in navigation mode. useEffect( () => { @@ -363,4 +363,4 @@ function BlockSelectionButton( { clientId, rootClientId } ) { ); } -export default BlockSelectionButton; +export default forwardRef( BlockSelectionButton ); diff --git a/packages/block-editor/src/components/block-tools/block-toolbar-breadcrumb.js b/packages/block-editor/src/components/block-tools/block-toolbar-breadcrumb.js index 0ae67e1be0001e..ae03bdb4f51647 100644 --- a/packages/block-editor/src/components/block-tools/block-toolbar-breadcrumb.js +++ b/packages/block-editor/src/components/block-tools/block-toolbar-breadcrumb.js @@ -3,6 +3,11 @@ */ import clsx from 'clsx'; +/** + * WordPress dependencies + */ +import { forwardRef } from '@wordpress/element'; + /** * Internal dependencies */ @@ -11,10 +16,7 @@ import { PrivateBlockPopover } from '../block-popover'; import useBlockToolbarPopoverProps from './use-block-toolbar-popover-props'; import useSelectedBlockToolProps from './use-selected-block-tool-props'; -export default function BlockToolbarBreadcrumb( { - clientId, - __unstableContentRef, -} ) { +function BlockToolbarBreadcrumb( { clientId, __unstableContentRef }, ref ) { const { capturingClientId, isInsertionPointVisible, @@ -38,9 +40,12 @@ export default function BlockToolbarBreadcrumb( { { ...popoverProps } > ); } + +export default forwardRef( BlockToolbarBreadcrumb ); diff --git a/packages/block-editor/src/components/block-tools/index.js b/packages/block-editor/src/components/block-tools/index.js index 5501f7d85a3cd4..698f340fc26693 100644 --- a/packages/block-editor/src/components/block-tools/index.js +++ b/packages/block-editor/src/components/block-tools/index.js @@ -93,6 +93,8 @@ export default function BlockTools( { expandBlock, } = unlock( useDispatch( blockEditorStore ) ); + const blockSelectionButtonRef = useRef(); + function onKeyDown( event ) { if ( event.defaultPrevented ) { return; @@ -153,7 +155,10 @@ export default function BlockTools( { // block so that focus is directed back to the beginning of the selection. // In effect, to the user this feels like deselecting the multi-selection. selectBlock( clientIds[ 0 ] ); - } else if ( clientIds.length === 1 ) { + } else if ( + clientIds.length === 1 && + event.target === blockSelectionButtonRef?.current + ) { event.preventDefault(); clearSelectedBlock(); @@ -204,7 +209,6 @@ export default function BlockTools( { } } } - const blockToolbarRef = usePopoverScroll( __unstableContentRef ); const blockToolbarAfterRef = usePopoverScroll( __unstableContentRef ); @@ -235,6 +239,7 @@ export default function BlockTools( { { showBreadcrumb && ( diff --git a/packages/components/src/higher-order/navigate-regions/style.scss b/packages/components/src/higher-order/navigate-regions/style.scss index 914856a9b2f1fe..f4f222ed672e9c 100644 --- a/packages/components/src/higher-order/navigate-regions/style.scss +++ b/packages/components/src/higher-order/navigate-regions/style.scss @@ -3,7 +3,7 @@ position: relative; // Handles the focus when we programatically send focus to this region - &:focus-visible::after { + &.interface-interface-skeleton__content:focus-visible::after { position: absolute; top: 0; left: 0;