Skip to content

Commit 232b6f9

Browse files
committed
Keep inserters visible on scroll
1 parent aea561a commit 232b6f9

File tree

3 files changed

+11
-54
lines changed

3 files changed

+11
-54
lines changed

packages/block-editor/src/components/block-popover/inbetween.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,13 @@ function BlockPopoverInbetween( {
9898
width,
9999
height: previousRect ? previousRect.height : nextRect.height,
100100
};
101-
}, [ previousElement, nextElement, isVertical, positionRecompute ] );
101+
}, [
102+
previousElement,
103+
nextElement,
104+
isVertical,
105+
positionRecompute,
106+
isVisible,
107+
] );
102108

103109
const getAnchorRect = useCallback( () => {
104110
if ( ( ! previousElement && ! nextElement ) || ! isVisible ) {
@@ -159,7 +165,7 @@ function BlockPopoverInbetween( {
159165
width: 0,
160166
ownerDocument,
161167
};
162-
}, [ previousElement, nextElement, positionRecompute ] );
168+
}, [ previousElement, nextElement, positionRecompute, isVisible ] );
163169

164170
const popoverScrollRef = usePopoverScroll( __unstableContentRef );
165171

packages/block-editor/src/components/block-popover/style.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
// like the popover is impacted by the block gap margin.
77
margin: 0 !important;
88

9+
// Allow clicking through the toolbar holder.
10+
pointer-events: none;
11+
912
.components-popover__content {
1013
margin: 0 !important;
1114
min-width: auto;
@@ -16,8 +19,6 @@
1619
box-shadow: none;
1720
overflow-y: visible;
1821

19-
// Allow clicking through the toolbar holder.
20-
pointer-events: none;
2122
> div > * {
2223
pointer-events: all;
2324
}

packages/block-editor/src/components/block-tools/exploded-mode-inserters.js

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,20 @@
1-
/**
2-
* External dependencies
3-
*/
4-
import { throttle } from 'lodash';
5-
61
/**
72
* WordPress dependencies
83
*/
94
import { useSelect } from '@wordpress/data';
10-
import { useState, useEffect } from '@wordpress/element';
115

126
/**
137
* Internal dependencies
148
*/
159
import BlockPopoverInbetween from '../block-popover/inbetween';
1610
import { store as blockEditorStore } from '../../store';
1711
import Inserter from '../inserter';
18-
import { __unstableUseBlockElement } from '../block-list/use-block-props/use-block-refs';
19-
20-
function useIsScrolling() {
21-
const [ isScrolling, setIsScrolling ] = useState( false );
22-
23-
const clientId = useSelect( ( select ) => {
24-
return select( blockEditorStore ).getBlockOrder()?.[ 0 ];
25-
}, [] );
26-
const element = __unstableUseBlockElement( clientId );
27-
28-
useEffect( () => {
29-
let timeout;
30-
setIsScrolling( false );
31-
if ( ! element ) {
32-
return;
33-
}
34-
const onScroll = throttle( () => {
35-
setIsScrolling( true );
36-
clearTimeout( timeout );
37-
timeout = setTimeout( () => {
38-
setIsScrolling( false );
39-
}, 100 );
40-
}, 100 );
41-
42-
element.ownerDocument.defaultView.addEventListener(
43-
'scroll',
44-
onScroll
45-
);
46-
return () => {
47-
clearTimeout( timeout );
48-
element.ownerDocument.defaultView.removeEventListener(
49-
'scroll',
50-
onScroll
51-
);
52-
};
53-
}, [ element ] );
54-
55-
return isScrolling;
56-
}
5712

5813
function ExplodedModeInserters( { __unstableContentRef } ) {
59-
const isScrolling = useIsScrolling();
6014
const blockOrder = useSelect( ( select ) => {
6115
return select( blockEditorStore ).getBlockOrder();
6216
}, [] );
6317

64-
if ( isScrolling ) {
65-
return null;
66-
}
67-
6818
return blockOrder.map( ( clientId, index ) => {
6919
if ( index === blockOrder.length - 1 ) {
7020
return null;

0 commit comments

Comments
 (0)