Skip to content

Commit

Permalink
Remove padding prop from popover (#40544)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored Apr 28, 2022
1 parent 06d1c48 commit b99e668
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export default function BlockPopover( {
__unstableBoundaryParent
// Observe movement for block animations (especially horizontal).
__unstableObserveElement={ selectedElement }
shouldAnchorIncludePadding
// Used to safeguard sticky position behavior against cases where it would permanently
// obscure specific sections of a block.
__unstableEditorCanvasWrapper={ __unstableContentRef?.current }
Expand Down
56 changes: 5 additions & 51 deletions packages/components/src/popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ function computeAnchorRect(
anchorRect,
getAnchorRect,
anchorRef = false,
shouldAnchorIncludePadding,
container
) {
if ( anchorRect ) {
Expand Down Expand Up @@ -98,17 +97,14 @@ function computeAnchorRect(
container
);

if ( shouldAnchorIncludePadding ) {
return rect;
}

return withoutPadding( rect, anchorRef );
return rect;
}

const { top, bottom } = anchorRef;
const topRect = top.getBoundingClientRect();
const bottomRect = bottom.getBoundingClientRect();
const rect = offsetIframe(

return offsetIframe(
new window.DOMRect(
topRect.left,
topRect.top,
Expand All @@ -118,58 +114,19 @@ function computeAnchorRect(
top.ownerDocument,
container
);

if ( shouldAnchorIncludePadding ) {
return rect;
}

return withoutPadding( rect, anchorRef );
}

if ( ! anchorRefFallback.current ) {
return;
}

const { parentNode } = anchorRefFallback.current;
const rect = offsetIframe(

return offsetIframe(
parentNode.getBoundingClientRect(),
parentNode.ownerDocument,
container
);

if ( shouldAnchorIncludePadding ) {
return rect;
}

return withoutPadding( rect, parentNode );
}

function getComputedStyle( node ) {
return node.ownerDocument.defaultView.getComputedStyle( node );
}

function withoutPadding( rect, element ) {
const {
paddingTop,
paddingBottom,
paddingLeft,
paddingRight,
} = getComputedStyle( element );
const top = paddingTop ? parseInt( paddingTop, 10 ) : 0;
const bottom = paddingBottom ? parseInt( paddingBottom, 10 ) : 0;
const left = paddingLeft ? parseInt( paddingLeft, 10 ) : 0;
const right = paddingRight ? parseInt( paddingRight, 10 ) : 0;

return {
x: rect.left + left,
y: rect.top + top,
width: rect.width - left - right,
height: rect.height - top - bottom,
left: rect.left + left,
right: rect.right - right,
top: rect.top + top,
bottom: rect.bottom - bottom,
};
}

/**
Expand Down Expand Up @@ -252,7 +209,6 @@ const Popover = (
range,
focusOnMount = 'firstElement',
anchorRef,
shouldAnchorIncludePadding,
anchorRect,
getAnchorRect,
expandOnMobile,
Expand Down Expand Up @@ -304,7 +260,6 @@ const Popover = (
anchorRect,
getAnchorRect,
anchorRef,
shouldAnchorIncludePadding,
containerRef.current
);

Expand Down Expand Up @@ -480,7 +435,6 @@ const Popover = (
anchorRect,
getAnchorRect,
anchorRef,
shouldAnchorIncludePadding,
position,
contentSize,
__unstableStickyBoundaryElement,
Expand Down
1 change: 0 additions & 1 deletion packages/nux/src/components/dot-tip/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export function DotTip( {
position={ position }
noArrow
focusOnMount="container"
shouldAnchorIncludePadding
role="dialog"
aria-label={ __( 'Editor tips' ) }
onClick={ onClick }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ exports[`DotTip should render correctly 1`] = `
onFocusOutside={[Function]}
position="middle right"
role="dialog"
shouldAnchorIncludePadding={true}
>
<p>
It looks like you’re writing a letter. Would you like help?
Expand Down

0 comments on commit b99e668

Please sign in to comment.