-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
ListViewDropIndicator: use Popover's new anchor prop #43694
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,40 +68,41 @@ export default function ListViewDropIndicator( { | |
}; | ||
}, [ getDropIndicatorIndent, targetElement ] ); | ||
|
||
const getAnchorRect = useCallback( () => { | ||
if ( ! targetElement ) { | ||
return {}; | ||
const popoverAnchor = useMemo( () => { | ||
const isValidDropPosition = | ||
dropPosition === 'top' || | ||
dropPosition === 'bottom' || | ||
dropPosition === 'inside'; | ||
if ( ! targetElement || ! isValidDropPosition ) { | ||
return undefined; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change no. 1: return |
||
} | ||
|
||
const ownerDocument = targetElement.ownerDocument; | ||
const rect = targetElement.getBoundingClientRect(); | ||
const indent = getDropIndicatorIndent(); | ||
|
||
const anchorRect = { | ||
left: rect.left + indent, | ||
right: rect.right, | ||
width: 0, | ||
height: 0, | ||
ownerDocument, | ||
return { | ||
ownerDocument: targetElement.ownerDocument, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change no. 3: |
||
getBoundingClientRect() { | ||
const rect = targetElement.getBoundingClientRect(); | ||
const indent = getDropIndicatorIndent(); | ||
|
||
const left = rect.left + indent; | ||
const right = rect.right; | ||
let top = 0; | ||
let bottom = 0; | ||
|
||
if ( dropPosition === 'top' ) { | ||
top = rect.top; | ||
bottom = rect.top; | ||
} else { | ||
// `dropPosition` is either `bottom` or `inside` | ||
top = rect.bottom; | ||
bottom = rect.bottom; | ||
} | ||
|
||
const width = right - left; | ||
const height = bottom - top; | ||
|
||
return new window.DOMRect( left, top, width, height ); | ||
Comment on lines
+83
to
+103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change no. 4: the logic was kept unchanged, but moved inside the Instead of returning a "handmade" rect-like object, we use |
||
}, | ||
}; | ||
|
||
if ( dropPosition === 'top' ) { | ||
return { | ||
...anchorRect, | ||
top: rect.top, | ||
bottom: rect.top, | ||
}; | ||
} | ||
|
||
if ( dropPosition === 'bottom' || dropPosition === 'inside' ) { | ||
return { | ||
...anchorRect, | ||
top: rect.bottom, | ||
bottom: rect.bottom, | ||
}; | ||
} | ||
|
||
return {}; | ||
}, [ targetElement, dropPosition, getDropIndicatorIndent ] ); | ||
|
||
if ( ! targetElement ) { | ||
|
@@ -111,7 +112,7 @@ export default function ListViewDropIndicator( { | |
return ( | ||
<Popover | ||
animate={ false } | ||
getAnchorRect={ getAnchorRect } | ||
anchor={ popoverAnchor } | ||
focusOnMount={ false } | ||
className="block-editor-list-view-drop-indicator" | ||
> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change no. 2: instead of returning an empty object at the end of this function if
dropPosition
didn't have the required values, I moved that check at the start of the function.