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

Block popover: fix scrolling over #68075

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
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 @@ -2,24 +2,29 @@
* WordPress dependencies
*/
import { useRefEffect } from '@wordpress/compose';
import { getScrollContainer } from '@wordpress/dom';

const scrollContainerCache = new WeakMap();

/**
* Allow scrolling "through" popovers over the canvas. This is only called for
* as long as the pointer is over a popover. Do not use React events because it
* will bubble through portals.
*
* @param {Object} scrollableRef
* @param {Object} contentRef
*/
function usePopoverScroll( scrollableRef ) {
function usePopoverScroll( contentRef ) {
return useRefEffect(
( node ) => {
if ( ! scrollableRef ) {
return;
}

function onWheel( event ) {
const { deltaX, deltaY } = event;
scrollableRef.current.scrollBy( deltaX, deltaY );
const contentEl = contentRef.current;
let scrollContainer = scrollContainerCache.get( contentEl );
if ( ! scrollContainer ) {
scrollContainer = getScrollContainer( contentEl );
scrollContainerCache.set( contentEl, scrollContainer );
}
scrollContainer.scrollBy( deltaX, deltaY );
}
// Tell the browser that we do not call event.preventDefault
// See https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#improving_scrolling_performance_with_passive_listeners
Expand All @@ -29,7 +34,7 @@ function usePopoverScroll( scrollableRef ) {
node.removeEventListener( 'wheel', onWheel, options );
};
},
[ scrollableRef ]
[ contentRef ]
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useShortcut } from '@wordpress/keyboard-shortcuts';
/**
* Internal dependencies
*/
import BlockPopover from '../block-popover';
import { PrivateBlockPopover } from '../block-popover';
import useBlockToolbarPopoverProps from './use-block-toolbar-popover-props';
import useSelectedBlockToolProps from './use-selected-block-tool-props';
import { store as blockEditorStore } from '../../store';
Expand Down Expand Up @@ -58,14 +58,15 @@ export default function BlockToolbarPopover( {

return (
! isTyping && (
<BlockPopover
<PrivateBlockPopover
clientId={ clientIdToPositionOver }
bottomClientId={ lastClientId }
className={ clsx( 'block-editor-block-list__block-popover', {
'is-insertion-point-visible': isInsertionPointVisible,
} ) }
resize={ false }
{ ...popoverProps }
__unstableContentRef={ __unstableContentRef }
>
<PrivateBlockToolbar
// If the toolbar is being shown because of being forced
Expand All @@ -79,7 +80,7 @@ export default function BlockToolbarPopover( {
} }
variant="toolbar"
/>
</BlockPopover>
</PrivateBlockPopover>
)
);
}
Loading