Skip to content
Merged
Show file tree
Hide file tree
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 @@ -132,6 +132,7 @@ function SelectedBlockPopover( {
} ) }
__unstablePopoverSlot={ __unstablePopoverSlot }
__unstableContentRef={ __unstableContentRef }
resize={ false }
{ ...popoverProps }
>
{ shouldShowContextualToolbar && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@ import { __unstableUseBlockElement as useBlockElement } from '../block-list/use-
// down the toolbar will stay on screen by adopting a sticky position at the
// top of the viewport.
const DEFAULT_PROPS = {
resize: false,
flip: false,
__unstableShift: true,
};

// When there isn't enough height between the top of the block and the editor
// canvas, the `shift` prop is set to `false`, as it will cause the block to be
// obscured. The `flip` behavior is enabled, which positions the toolbar below
// the block.
// the block. This only happens if the block is smaller than the viewport, as
// otherwise the toolbar will be off-screen.
const RESTRICTED_HEIGHT_PROPS = {
resize: false,
flip: true,
__unstableShift: false,
};
Expand All @@ -47,7 +46,16 @@ function getProps( contentElement, selectedBlockElement, toolbarHeight ) {
const blockRect = selectedBlockElement.getBoundingClientRect();
const contentRect = contentElement.getBoundingClientRect();

if ( blockRect.top - contentRect.top > toolbarHeight ) {
// The document element's clientHeight represents the viewport height.
const viewportHeight =
contentElement.ownerDocument.documentElement.clientHeight;

const hasSpaceForToolbarAbove =
blockRect.top - contentRect.top > toolbarHeight;
const isBlockTallerThanViewport =
blockRect.height > viewportHeight - toolbarHeight;

if ( hasSpaceForToolbarAbove || isBlockTallerThanViewport ) {
return DEFAULT_PROPS;
}

Expand Down