From 57e2f6759d3fea0a466b75b85734d9d421b3306b Mon Sep 17 00:00:00 2001 From: Jerry Jones Date: Fri, 3 Nov 2023 16:15:13 -0500 Subject: [PATCH] Only render top toolbar in header slot if large viewport There were two forms of the small screen top toolbar -- one when the top toolbar option was on, and one when it was off. Both were intended to look and operate in the same way. Rather than maintain two identical systems, it makes more sense to only have one. This also makes the visual and tab order match for all versions, which is better accessibility too. --- .../src/components/block-toolbar/style.scss | 8 ++ .../src/components/block-tools/index.js | 35 +++++---- .../edit-post/src/components/header/index.js | 2 +- .../src/components/header/style.scss | 16 +--- .../src/components/header-edit-mode/index.js | 8 +- .../components/header-edit-mode/style.scss | 7 +- .../src/components/layout/style.scss | 9 --- .../src/components/header/index.js | 3 +- .../src/components/header/style.scss | 17 +--- .../various/keyboard-navigable-blocks.spec.js | 78 +++++++++++++++++++ 10 files changed, 122 insertions(+), 61 deletions(-) diff --git a/packages/block-editor/src/components/block-toolbar/style.scss b/packages/block-editor/src/components/block-toolbar/style.scss index eef1678e2dfab..3f8a7057aef84 100644 --- a/packages/block-editor/src/components/block-toolbar/style.scss +++ b/packages/block-editor/src/components/block-toolbar/style.scss @@ -56,6 +56,14 @@ } } +.block-editor-block-contextual-toolbar.is-fixed { + position: sticky; + top: 0; + z-index: z-index(".block-editor-block-popover"); + display: block; + width: 100%; +} + // on desktop browsers the fixed toolbar has tweaked borders @include break-medium() { .block-editor-block-contextual-toolbar.is-fixed { diff --git a/packages/block-editor/src/components/block-tools/index.js b/packages/block-editor/src/components/block-tools/index.js index de4ada16a7dd4..884bda02e75f9 100644 --- a/packages/block-editor/src/components/block-tools/index.js +++ b/packages/block-editor/src/components/block-tools/index.js @@ -170,6 +170,13 @@ export default function BlockTools( { const blockToolbarRef = usePopoverScroll( __unstableContentRef ); const blockToolbarAfterRef = usePopoverScroll( __unstableContentRef ); + // Conditions for fixed toolbar + // 1. Not zoom out mode + // 2. It's a large viewport. If it's a smaller viewport, let the floating toolbar handle it as it already has styles attached to make it render that way. + // 3. Fixed toolbar is enabled + const isTopToolbar = ! isZoomOutMode && hasFixedToolbar && isLargeViewport; + const isTopToolbarFill = isTopToolbar && blockToolsSlot?.ref?.current; + return ( // eslint-disable-next-line jsx-a11y/no-static-element-interactions
@@ -180,21 +187,23 @@ export default function BlockTools( { /> ) } { /* If there is no slot available, such as in the standalone block editor, render within the editor */ } - { ! isZoomOutMode && - ( hasFixedToolbar || ! isLargeViewport ) && - ( blockToolsSlot?.ref?.current ? ( - - - - ) : ( + { isTopToolbarFill && ( + - ) ) } + + ) } + + { ! isTopToolbarFill && + ( isTopToolbar || ! isLargeViewport ) && ( // Small viewports always get a fixed toolbar + + ) } + { showEmptyBlockSideInserter && ( - { hasFixedToolbar && ( + { hasFixedToolbar && isLargeViewport && ( - { hasFixedToolbar && ( + { hasFixedToolbar && isLargeViewport && ( <> - { isLargeViewport && hasBlockSelected && ( + { hasBlockSelected && (