Skip to content

Commit

Permalink
Hide ghost top toolbar (#54555)
Browse files Browse the repository at this point in the history
* hide white rectangle caused by the fixed block toolbar

* fix bug that kept calculated width on rendered block toolbar even if no block was selected
  • Loading branch information
draganescu authored Sep 19, 2023
1 parent 83d76e1 commit fde0956
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,15 @@ function BlockContextualToolbar( { focusOnMount, isFixed, ...props } ) {
const isFullscreen =
document.body.classList.contains( 'is-fullscreen-mode' );

/**
* The following code is a workaround to fix the width of the toolbar
* it should be removed when the toolbar will be rendered inline
* FIXME: remove this layout effect when the toolbar is no longer
* absolutely positioned
*/
useLayoutEffect( () => {
// don't do anything if not fixed toolbar
if ( ! isFixed || ! blockType ) {
if ( ! isFixed ) {
return;
}

Expand All @@ -100,6 +106,11 @@ function BlockContextualToolbar( { focusOnMount, isFixed, ...props } ) {
return;
}

if ( ! blockType ) {
blockToolbar.style.width = 'initial';
return;
}

if ( ! isLargerThanTabletViewport ) {
// set the width of the toolbar to auto
blockToolbar.style = {};
Expand All @@ -116,7 +127,6 @@ function BlockContextualToolbar( { focusOnMount, isFixed, ...props } ) {
const pinnedItems = document.querySelector(
'.edit-post-header__settings, .edit-widgets-header__actions'
);

// get the width of the left header in the site editor
const leftHeader = document.querySelector(
'.edit-site-header-edit-mode__end'
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-site/src/components/block-editor/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
contextual toolbar has been redesigned.
See: https://github.com/WordPress/gutenberg/issues/40450
*/
.block-editor-block-contextual-toolbar {
.block-editor-block-contextual-toolbar.is-fixed {
display: none;
}
}
Expand Down

1 comment on commit fde0956

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in fde0956.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6235693470
📝 Reported issues:

Please sign in to comment.