Skip to content

Commit 1dc0ef3

Browse files
authored
fix: Display drag-and-drop indicator (#217)
Communicate the destination position for a dragged block. The popover used for this feature was hidden previously because it disrupts tap/click events in the block inserter, requiring two taps to insert a block. These changes continue hiding the "add block" button popover displayed alongside empty text blocks, but allows the insertion point indicator to now be displayed. We disable the insertion point display from the block inserter only by detecting touch devices (as best possible) and prevent the relevant `onMouseEnter` event callback triggering the `onHover` callback.
1 parent 4083304 commit 1dc0ef3

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

patches/@wordpress+block-editor+14.17.0.patch

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
diff --git a/node_modules/@wordpress/block-editor/build-module/components/inserter-list-item/index.js b/node_modules/@wordpress/block-editor/build-module/components/inserter-list-item/index.js
2+
index 89a3bbc..8564798 100644
3+
--- a/node_modules/@wordpress/block-editor/build-module/components/inserter-list-item/index.js
4+
+++ b/node_modules/@wordpress/block-editor/build-module/components/inserter-list-item/index.js
5+
@@ -28,6 +28,10 @@ function InserterListItem({
6+
...props
7+
}) {
8+
const isDraggingRef = useRef(false);
9+
+ const isTouchDeviceRef = useRef(
10+
+ window.matchMedia( '(hover: none)' ).matches ||
11+
+ window.matchMedia( '(pointer: coarse)' ).matches
12+
+ );
13+
const itemIconStyle = item.icon ? {
14+
backgroundColor: item.icon.background,
15+
color: item.icon.foreground
16+
@@ -80,7 +84,7 @@ function InserterListItem({
17+
}
18+
},
19+
onMouseEnter: () => {
20+
- if (isDraggingRef.current) {
21+
+ if (isDraggingRef.current || isTouchDeviceRef.current) {
22+
return;
23+
}
24+
onHover(item);
125
diff --git a/node_modules/@wordpress/block-editor/build-module/components/inserter/index.js b/node_modules/@wordpress/block-editor/build-module/components/inserter/index.js
226
index 78b9b8f..9a8efb8 100644
327
--- a/node_modules/@wordpress/block-editor/build-module/components/inserter/index.js

patches/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Existing patches should be described and justified here.
1111
- Expose an `open` prop on the `Inserter` component, allowing toggling the inserter visibility via the quick inserter's "Browse all" button.
1212
- Disable `stripExperimentalSettings` in the `BlockEditorProvider` component so that the Patterns and Media inserter tabs function.
1313
- Allow setting popover props for the `Inserter` component, so we can improve the mobile screen reader experience by marking it as a modal dialog.
14+
- Prevent the insertion point popover from appearing on touch devices in `InserterListItem`. The popover (triggered by `onMouseEnter`) disrupts tap/click events, requiring users to tap inserter items twice before they are inserted.
1415

1516
### `@wordpress/block-library`
1617

src/components/visual-editor/style.scss

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,12 @@
9090
width: 100%;
9191
}
9292

93-
// Hide the inserter popover displayed between blocks when hovering between
94-
// blocks or hovering over a block type in the inserter. Its presence is less
95-
// useful for touch devices and steals focus away from the inserter, which
96-
// results in needing to tap a block type twice to insert it.
97-
.gutenberg-kit-visual-editor .block-editor-block-popover {
93+
// Hide the inline inserter popover displayed from the "Add block" button
94+
// positioned alongside empty text blocks. Its presence is less useful for touch
95+
// devices and steals focus away from the inserter, which results in needing to
96+
// tap a block type twice to insert it.
97+
.gutenberg-kit-visual-editor
98+
.block-editor-block-list__block-side-inserter-popover {
9899
display: none;
99100
}
100101

src/index.scss

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ $baseline-interactive-font-size: 17px;
7373
width: 320px;
7474
}
7575

76-
// Hide the inline insterter shown inside the block list
77-
.block-editor-block-list__block-side-inserter-popover {
78-
display: none;
79-
}
80-
8176
/* Inserter (Mobile Design) */
8277

8378
// Inserter tab buttons

0 commit comments

Comments
 (0)