Skip to content

Commit cd2ac50

Browse files
committed
ListViewDropIndicator: use Popover s new anchor prop (#43694)
1 parent d19e583 commit cd2ac50

File tree

1 file changed

+33
-32
lines changed

1 file changed

+33
-32
lines changed

packages/block-editor/src/components/list-view/drop-indicator.js

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -68,40 +68,41 @@ export default function ListViewDropIndicator( {
6868
};
6969
}, [ getDropIndicatorIndent, targetElement ] );
7070

71-
const getAnchorRect = useCallback( () => {
72-
if ( ! targetElement ) {
73-
return {};
71+
const popoverAnchor = useMemo( () => {
72+
const isValidDropPosition =
73+
dropPosition === 'top' ||
74+
dropPosition === 'bottom' ||
75+
dropPosition === 'inside';
76+
if ( ! targetElement || ! isValidDropPosition ) {
77+
return undefined;
7478
}
7579

76-
const ownerDocument = targetElement.ownerDocument;
77-
const rect = targetElement.getBoundingClientRect();
78-
const indent = getDropIndicatorIndent();
79-
80-
const anchorRect = {
81-
left: rect.left + indent,
82-
right: rect.right,
83-
width: 0,
84-
height: 0,
85-
ownerDocument,
80+
return {
81+
ownerDocument: targetElement.ownerDocument,
82+
getBoundingClientRect() {
83+
const rect = targetElement.getBoundingClientRect();
84+
const indent = getDropIndicatorIndent();
85+
86+
const left = rect.left + indent;
87+
const right = rect.right;
88+
let top = 0;
89+
let bottom = 0;
90+
91+
if ( dropPosition === 'top' ) {
92+
top = rect.top;
93+
bottom = rect.top;
94+
} else {
95+
// `dropPosition` is either `bottom` or `inside`
96+
top = rect.bottom;
97+
bottom = rect.bottom;
98+
}
99+
100+
const width = right - left;
101+
const height = bottom - top;
102+
103+
return new window.DOMRect( left, top, width, height );
104+
},
86105
};
87-
88-
if ( dropPosition === 'top' ) {
89-
return {
90-
...anchorRect,
91-
top: rect.top,
92-
bottom: rect.top,
93-
};
94-
}
95-
96-
if ( dropPosition === 'bottom' || dropPosition === 'inside' ) {
97-
return {
98-
...anchorRect,
99-
top: rect.bottom,
100-
bottom: rect.bottom,
101-
};
102-
}
103-
104-
return {};
105106
}, [ targetElement, dropPosition, getDropIndicatorIndent ] );
106107

107108
if ( ! targetElement ) {
@@ -111,7 +112,7 @@ export default function ListViewDropIndicator( {
111112
return (
112113
<Popover
113114
animate={ false }
114-
getAnchorRect={ getAnchorRect }
115+
anchor={ popoverAnchor }
115116
focusOnMount={ false }
116117
className="block-editor-list-view-drop-indicator"
117118
>

0 commit comments

Comments
 (0)