Skip to content
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

Refactor the Popover component to use the floatingUI library #40740

Merged
merged 41 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
07cc373
Refactor the Popover component to use the floatingUI library
youknowriad Apr 29, 2022
e2fc1a7
Remove placement prop + small fixes
youknowriad May 4, 2022
0926333
Fix inbetween inserter position
youknowriad May 4, 2022
9d9e748
Some style tweaks
youknowriad May 4, 2022
6076815
Position the color popover properly
youknowriad May 4, 2022
4488e44
Simplify BlockAlignmentMatrixControl popover styles
youknowriad May 4, 2022
a534b64
Simplify block switcher popover CSS
youknowriad May 4, 2022
6705ae8
Better position for the Cover overlay color popover
youknowriad May 4, 2022
4bf13c0
More popover styles tweaks
youknowriad May 4, 2022
b17c576
hide popover when not within the same clipping context
ntsekouras May 4, 2022
7610e5c
Add the iframe offset middleware
youknowriad May 9, 2022
0638623
Revert hide middleware to fix inbetween inserter in site editor
youknowriad May 9, 2022
5180083
Add shift limit and support multi selections
youknowriad May 9, 2022
e342f8b
Remove flyout from manifest
youknowriad May 9, 2022
52ba2d7
Add back animation
youknowriad May 9, 2022
3354ad6
Fix popover unit test
youknowriad May 9, 2022
f3effa8
Fix support for range popovers
youknowriad May 9, 2022
695e11a
Restore default dropdown gutter
youknowriad May 10, 2022
8501d2f
Restore tooltip position
youknowriad May 10, 2022
2eceda7
Fix color palette position
youknowriad May 10, 2022
5166b37
Position the border-box-control popovers correctly
youknowriad May 10, 2022
6367d4d
Fix unit tests
youknowriad May 10, 2022
3e66b1f
Fix e2e test
youknowriad May 10, 2022
c11ff65
Fix animation origin
youknowriad May 10, 2022
b52b0c7
Deprecate range prop
youknowriad May 11, 2022
2fe712f
Update Popover README
youknowriad May 11, 2022
8a8fcea
Add comment to explain offset value
youknowriad May 11, 2022
38014cf
Change the type of popoverProps
youknowriad May 11, 2022
f0eebe0
Fix position shifting
youknowriad May 12, 2022
b7ce415
Remove extra div from popover
youknowriad May 12, 2022
4ba2005
Apply suggestions from code review (documentation)
youknowriad May 12, 2022
43c4ff9
documentation fix
youknowriad May 12, 2022
abad260
Fix correct classname for border control dropdown.
youknowriad May 12, 2022
7aff278
Better border box props documentation
youknowriad May 12, 2022
64e051d
Simplify border control popover styles
youknowriad May 12, 2022
d9ec0bb
Fix more menu size
youknowriad May 12, 2022
87fb541
Add the max size behavior
youknowriad May 12, 2022
8e433bb
Fix border control popover styles
youknowriad May 16, 2022
3a0c29a
Fix image zoom popover
youknowriad May 16, 2022
3caf4b4
Fix scroll shifts when focusing popovers
youknowriad May 16, 2022
662002c
fix custom color test
ntsekouras May 17, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -815,12 +815,6 @@
"markdown_source": "../packages/components/src/flex/flex/README.md",
"parent": "components"
},
{
"title": "Flyout",
"slug": "flyout",
"markdown_source": "../packages/components/src/flyout/flyout/README.md",
"parent": "components"
},
{
"title": "FocalPointPicker",
"slug": "focal-point-picker",
Expand Down
26 changes: 24 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@ function BlockAlignmentMatrixControl( props ) {
} = props;

const icon = <AlignmentMatrixControl.Icon value={ value } />;
const className = 'block-editor-block-alignment-matrix-control';
const popoverClassName = `${ className }__popover`;
const isAlternate = true;

return (
<Dropdown
position="bottom right"
className={ className }
popoverProps={ { className: popoverClassName, isAlternate } }
popoverProps={ { isAlternate: true } }
renderToggle={ ( { onToggle, isOpen } ) => {
const openOnArrowDown = ( event ) => {
if ( ! isOpen && event.keyCode === DOWN ) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ function BlockPopoverInbetween( {
left: previousRect ? previousRect.right : nextRect.right,
right: previousRect ? previousRect.left : nextRect.left,
bottom: nextRect ? nextRect.top : previousRect.bottom,
height: 0,
width: 0,
ownerDocument,
};
}
Expand All @@ -116,6 +118,8 @@ function BlockPopoverInbetween( {
left: previousRect ? previousRect.left : nextRect.left,
right: previousRect ? previousRect.right : nextRect.right,
bottom: nextRect ? nextRect.top : previousRect.bottom,
height: 0,
width: 0,
ownerDocument,
};
}
Expand All @@ -126,6 +130,8 @@ function BlockPopoverInbetween( {
left: previousRect ? previousRect.left : nextRect.right,
right: nextRect ? nextRect.right : previousRect.left,
bottom: previousRect ? previousRect.bottom : nextRect.bottom,
height: 0,
width: 0,
ownerDocument,
};
}
Expand All @@ -135,6 +141,8 @@ function BlockPopoverInbetween( {
left: previousRect ? previousRect.right : nextRect.left,
right: nextRect ? nextRect.left : previousRect.right,
bottom: previousRect ? previousRect.bottom : nextRect.bottom,
height: 0,
width: 0,
ownerDocument,
};
}, [ previousElement, nextElement ] );
Expand All @@ -155,7 +163,6 @@ function BlockPopoverInbetween( {
return (
<Popover
ref={ popoverScrollRef }
noArrow
animate={ false }
getAnchorRect={ getAnchorRect }
focusOnMount={ false }
Expand Down
17 changes: 1 addition & 16 deletions packages/block-editor/src/components/block-popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import { Popover } from '@wordpress/components';
import { getScrollContainer } from '@wordpress/dom';
import { useMemo } from '@wordpress/element';

/**
Expand Down Expand Up @@ -50,33 +49,19 @@ export default function BlockPopover( {
bottom: lastSelectedElement,
};

const { ownerDocument } = selectedElement;
const stickyBoundaryElement =
ownerDocument.defaultView.frameElement ||
getScrollContainer( selectedElement ) ||
ownerDocument.body;

return (
<Popover
ref={ popoverScrollRef }
noArrow
animate={ false }
position="top right left"
focusOnMount={ false }
anchorRef={ anchorRef }
__unstableStickyBoundaryElement={
__unstableCoverTarget ? undefined : stickyBoundaryElement
}
// Render in the old slot if needed for backward compatibility,
// otherwise render in place (not in the the default popover slot).
__unstableSlotName={ __unstablePopoverSlot || null }
__unstableBoundaryParent
// Observe movement for block animations (especially horizontal).
__unstableObserveElement={ selectedElement }
// Used to safeguard sticky position behavior against cases where it would permanently
// obscure specific sections of a block.
__unstableEditorCanvasWrapper={ __unstableContentRef?.current }
__unstableForcePosition={ __unstableCoverTarget }
__unstableForcePosition
{ ...props }
className={ classnames(
'block-editor-block-popover',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
width: max-content;
background: none;
border: none;
outline: none;
box-shadow: none;
overflow-y: visible;

Expand Down
41 changes: 2 additions & 39 deletions packages/block-editor/src/components/block-switcher/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@
font-size: 14px;
}

// Indent the popover to match the button position.
.block-editor-block-switcher__popover {
margin-left: 6px;
}

.components-button.block-editor-block-switcher__no-switcher-icon {
display: flex;

Expand Down Expand Up @@ -93,43 +88,11 @@
min-width: 300px;
}

// We keep the min width the same for the border to work.
.components-popover.block-editor-block-switcher__popover .components-popover__content > div {
min-width: auto;
display: flex;
background: $white;
padding: 0;

.components-menu-group {
margin: 0;
}
}

.block-editor-block-switcher__popover .components-popover__content {

.block-editor-block-styles {
margin: 0 -3px; // Remove the panel body padding while keeping it for the title.
}

// Hide the bottom border on the last panel so it stacks with the popover.
.components-panel__body {
border: 0;

// Elevate this so the hover style is visible.
position: relative;
z-index: 1;
}

.components-panel__body + .components-panel__body {
border-top: $border-width solid $gray-200;
}
}

.block-editor-block-switcher__popover__preview__parent {
.block-editor-block-switcher__popover__preview__container {
position: absolute;
top: -$grid-unit-15;
left: calc(100% + #{$grid-unit-40});
left: calc(100% + #{$grid-unit-20});
}
}

Expand All @@ -138,7 +101,6 @@

// Position correctly. Needs specificity.
&.components-popover {
margin-left: $grid-unit-05;
margin-top: $grid-unit-15 - $border-width;
}

Expand All @@ -151,6 +113,7 @@
border: $border-width solid $gray-900;
background: $white;
border-radius: $radius-block-ui;
outline: none;
}

.block-editor-block-switcher__preview {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,16 @@ export default function ColorGradientSettingsDropdown( {
__experimentalIsRenderedInSidebar,
...props
} ) {
const dropdownPosition = __experimentalIsRenderedInSidebar
? 'bottom left'
: undefined;

const dropdownClassName = __experimentalIsItemGroup
? 'block-editor-panel-color-gradient-settings__dropdown'
: 'block-editor-tools-panel-color-gradient-settings__dropdown';
let popoverProps;
if ( __experimentalIsRenderedInSidebar ) {
popoverProps = {
placement: 'left-start',
offset: 36,
};
}

return (
// Only wrap with `ItemGroup` if these controls are being rendered
Expand Down Expand Up @@ -170,7 +173,7 @@ export default function ColorGradientSettingsDropdown( {
{ ...props }
>
<Dropdown
position={ dropdownPosition }
popoverProps={ popoverProps }
className={ dropdownClassName }
contentClassName="block-editor-panel-color-gradient-settings__dropdown-content"
renderToggle={ renderToggle( toggleSettings ) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,7 @@
}

.block-editor-panel-color-gradient-settings__dropdown-content .components-popover__content {
& > div {
width: $sidebar-width;
}
}

@include break-medium() {
.block-editor-panel-color-gradient-settings__dropdown-content {
.components-popover__content {
margin-right: #{ math.div($sidebar-width, 2) + $grid-unit-20 } !important;
}

&.is-from-top .components-popover__content {
margin-top: #{ -($grid-unit-60 + $grid-unit-15) } !important;
}

&.is-from-bottom .components-popover__content {
margin-bottom: #{ -($grid-unit-60 + $grid-unit-15) } !important;
}
}
width: $sidebar-width;
}

.block-editor-panel-color-gradient-settings__dropdown:last-child > div {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $popover-padding: $grid-unit-20;
$swatch-columns: math.floor(math.div($popover-width + $swatch-gap - 2 * $popover-padding, $swatch-size + $swatch-gap));

.block-editor-duotone-control__popover {
> .components-popover__content > div {
> .components-popover__content {
padding: $popover-padding;
width: $popover-width;
}
Expand All @@ -34,9 +34,3 @@ $swatch-columns: math.floor(math.div($popover-width + $swatch-gap - 2 * $popover
margin: $grid-unit-20 0;
font-size: $helptext-font-size;
}

// Better align the popover under the swatch.
// @todo: when the positioning for popovers gets refactored, this can presumably be removed.
.block-editor-duotone-control__popover:not([data-y-axis="middle"][data-x-axis="right"]) > .components-popover__content {
margin-left: -14px;
}
3 changes: 2 additions & 1 deletion packages/block-editor/src/components/inserter/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ $block-inserter-tabs-height: 44px;
.block-editor-inserter__popover.is-quick {
.components-popover__content {
border: none;
outline: none;

.block-editor-inserter__quick-inserter > * {
border-left: $border-width solid $gray-400;
Expand Down Expand Up @@ -310,7 +311,7 @@ $block-inserter-tabs-height: 44px;
border-top: $border-width solid $gray-300;
}

.block-editor-inserter__popover.is-quick > .components-popover__content > div {
.block-editor-inserter__popover.is-quick > .components-popover__content {
padding: 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ export default function ListViewDropIndicator( {

return (
<Popover
noArrow
animate={ false }
getAnchorRect={ getAnchorRect }
focusOnMount={ false }
Expand Down
3 changes: 2 additions & 1 deletion packages/block-editor/src/components/list-view/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,11 @@ $block-navigation-max-indent: 8;
}

// Reset some popover defaults for the drop indicator.
.block-editor-list-view-drop-indicator:not([data-y-axis="middle"][data-x-axis="right"]) > .components-popover__content {
.block-editor-list-view-drop-indicator > .components-popover__content {
margin-left: 0;
border: none;
box-shadow: none;
outline: none;
}

.block-editor-list-view-placeholder {
Expand Down
14 changes: 12 additions & 2 deletions packages/block-editor/src/components/navigable-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ function hasFocusWithin( container ) {
function focusFirstTabbableIn( container ) {
const [ firstTabbable ] = focus.tabbable.find( container );
if ( firstTabbable ) {
firstTabbable.focus();
firstTabbable.focus( {
// When focusing newly mounted toolbars,
// the position of the popover is often not right on the first render
// This prevents the layout shifts when focusing the dialogs.
preventScroll: true,
} );
}
}

Expand Down Expand Up @@ -119,7 +124,12 @@ function useToolbarFocus(
const items = getAllToolbarItemsIn( ref.current );
const index = initialIndex || 0;
if ( items[ index ] && hasFocusWithin( ref.current ) ) {
items[ index ].focus();
items[ index ].focus( {
// When focusing newly mounted toolbars,
// the position of the popover is often not right on the first render
// This prevents the layout shifts when focusing the dialogs.
preventScroll: true,
} );
}
} );
}
Expand Down
Loading