Skip to content

Commit

Permalink
Block Popover: editor canvas as boundary (#19322)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored and Joen Asmussen committed Feb 6, 2020
1 parent 614d1aa commit ccfaa77
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ function BlockPopover( {
className="block-editor-block-list__block-popover"
__unstableSticky={ ! showEmptyBlockSideInserter }
__unstableSlotName="block-toolbar"
__unstableBoundaryParent
// Allow subpixel positioning for the block movement animation.
__unstableAllowVerticalSubpixelPosition={
moverDirection !== 'horizontal' && node
Expand All @@ -169,6 +170,9 @@ function BlockPopover( {
}
onBlur={ () => setIsToolbarForced( false ) }
shouldAnchorIncludePadding
// Popover calculates the width once. Trigger a reset by remounting
// the component.
key={ shouldShowContextualToolbar }
>
{ ( shouldShowContextualToolbar || isToolbarForced ) && (
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
.components-button.block-editor-block-switcher__no-switcher-icon {
width: $icon-button-size;

.block-editor-blocsk-icon {
.block-editor-blocks-icon {
margin-right: auto;
margin-left: auto;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/components/src/popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ const Popover = ( {
__unstableAllowVerticalSubpixelPosition,
__unstableAllowHorizontalSubpixelPosition,
__unstableFixedPosition = true,
__unstableBoundaryParent,
/* eslint-enable no-unused-vars */
...contentProps
} ) => {
Expand Down Expand Up @@ -471,6 +472,7 @@ const Popover = ( {
__unstableSticky,
__unstableAllowVerticalSubpixelPosition,
__unstableAllowHorizontalSubpixelPosition,
__unstableBoundaryParent,
] );

useFocusContentOnMount( focusOnMount, contentRef );
Expand Down Expand Up @@ -626,7 +628,7 @@ const Popover = ( {
const PopoverContainer = Popover;

PopoverContainer.Slot = ( { name = SLOT_NAME } ) => (
<Slot bubblesVirtually name={ name } />
<Slot bubblesVirtually name={ name } className="popover-slot" />
);

export default PopoverContainer;
9 changes: 8 additions & 1 deletion packages/components/src/popover/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const HEIGHT_OFFSET = 10; // used by the arrow and a bit of empty space
* scroll container edge when part of the anchor
* leaves view.
* @param {string} chosenYAxis yAxis to be used.
* @param {Element} boundaryElement
*
* @return {Object} Popover xAxis position and constraints.
*/
Expand All @@ -28,7 +29,8 @@ export function computePopoverXAxisPosition(
xAxis,
corner,
sticky,
chosenYAxis
chosenYAxis,
boundaryElement
) {
const { width } = contentSize;
const isRTL = document.documentElement.dir === 'rtl';
Expand Down Expand Up @@ -121,6 +123,11 @@ export function computePopoverXAxisPosition(
popoverLeft = rightAlignment.popoverLeft;
}

if ( boundaryElement ) {
const boundaryRect = boundaryElement.getBoundingClientRect();
popoverLeft = Math.min( popoverLeft, boundaryRect.right - width );
}

return {
xAxis: chosenXAxis,
popoverLeft,
Expand Down

0 comments on commit ccfaa77

Please sign in to comment.