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 Jan 23, 2020
1 parent 246ee5d commit 3c58cbb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,15 @@ function BlockPopover( {
className="block-editor-block-list__block-popover"
__unstableSticky={ showEmptyBlockSideInserter ? false : popoverIsSticky }
__unstableSlotName="block-toolbar"
__unstableBoundaryParent
// Allow subpixel positioning for the block movement animation.
__unstableAllowVerticalSubpixelPosition={ moverDirection !== 'horizontal' && node }
__unstableAllowHorizontalSubpixelPosition={ moverDirection === 'horizontal' && node }
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 @@ -228,6 +228,7 @@ const Popover = ( {
__unstableSlotName = SLOT_NAME,
__unstableAllowVerticalSubpixelPosition,
__unstableAllowHorizontalSubpixelPosition,
__unstableBoundaryParent,
/* eslint-enable no-unused-vars */
...contentProps
} ) => {
Expand Down Expand Up @@ -395,6 +396,7 @@ const Popover = ( {
__unstableSticky,
__unstableAllowVerticalSubpixelPosition,
__unstableAllowHorizontalSubpixelPosition,
__unstableBoundaryParent,
] );

useFocusContentOnMount( focusOnMount, contentRef );
Expand Down Expand Up @@ -532,6 +534,6 @@ const Popover = ( {
const PopoverContainer = Popover;

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

export default PopoverContainer;
8 changes: 7 additions & 1 deletion packages/components/src/popover/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ 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.
*/
export function computePopoverXAxisPosition( anchorRect, contentSize, xAxis, corner, sticky, chosenYAxis ) {
export function computePopoverXAxisPosition( anchorRect, contentSize, xAxis, corner, sticky, chosenYAxis, boundaryElement ) {
const { width } = contentSize;
const isRTL = document.documentElement.dir === 'rtl';

Expand Down Expand Up @@ -101,6 +102,11 @@ export function computePopoverXAxisPosition( anchorRect, contentSize, xAxis, cor
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 3c58cbb

Please sign in to comment.