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

Popover: stabilize __unstableShift prop to shift #43845

Merged
merged 7 commits into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function BlockPopover(
__unstableSlotName={ __unstablePopoverSlot || null }
resize={ false }
flip={ false }
__unstableShift
shift
{ ...props }
className={ classnames(
'block-editor-block-popover',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { __unstableUseBlockElement as useBlockElement } from '../block-list/use-
// top of the viewport.
const DEFAULT_PROPS = {
flip: false,
__unstableShift: true,
shift: true,
};

// When there isn't enough height between the top of the block and the editor
Expand All @@ -26,7 +26,7 @@ const DEFAULT_PROPS = {
// otherwise the toolbar will be off-screen.
const RESTRICTED_HEIGHT_PROPS = {
flip: true,
__unstableShift: false,
shift: false,
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export default function ColorGradientSettingsDropdown( {
popoverProps = {
placement: 'left-start',
offset: 36,
__unstableShift: true,
shift: true,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function URLPopover( {
className="block-editor-url-popover"
focusOnMount={ focusOnMount }
position={ position }
__unstableShift
shift
{ ...popoverProps }
>
<div className="block-editor-url-popover__input-container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

exports[`URLPopover matches the snapshot in its default state 1`] = `
<ForwardRef(Popover)
__unstableShift={true}
className="block-editor-url-popover"
focusOnMount="firstElement"
position="bottom center"
shift={true}
>
<div
className="block-editor-url-popover__input-container"
Expand Down Expand Up @@ -39,10 +39,10 @@ exports[`URLPopover matches the snapshot in its default state 1`] = `

exports[`URLPopover matches the snapshot when the settings are toggled open 1`] = `
<ForwardRef(Popover)
__unstableShift={true}
className="block-editor-url-popover"
focusOnMount="firstElement"
position="bottom center"
shift={true}
>
<div
className="block-editor-url-popover__input-container"
Expand Down Expand Up @@ -83,10 +83,10 @@ exports[`URLPopover matches the snapshot when the settings are toggled open 1`]

exports[`URLPopover matches the snapshot when there are no settings 1`] = `
<ForwardRef(Popover)
__unstableShift={true}
className="block-editor-url-popover"
focusOnMount="firstElement"
position="bottom center"
shift={true}
>
<div
className="block-editor-url-popover__input-container"
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/button/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function ButtonEdit( props ) {
anchorRef={ ref?.current }
focusOnMount={ isEditingURL ? 'firstElement' : false }
__unstableSlotName={ '__unstable-block-tools-after' }
__unstableShift
shift
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we intentionally keeping the legacy prop here:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, just a miss in my find-and-replace 🙈

Done in a8421c5

>
<LinkControl
className="wp-block-navigation-link__inline-link-input"
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/navigation-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ export default function NavigationLinkEdit( {
position="bottom center"
onClose={ () => setIsLinkOpen( false ) }
anchorRef={ listItemRef.current }
__unstableShift
shift
>
<LinkControl
hasTextControl
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/navigation-submenu/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ export default function NavigationSubmenuEdit( {
position="bottom center"
onClose={ () => setIsLinkOpen( false ) }
anchorRef={ listItemRef.current }
__unstableShift
shift
>
<LinkControl
className="wp-block-navigation-link__inline-link-input"
Expand Down
5 changes: 3 additions & 2 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@

### Enhancements

- `ToggleControl`: Add `__nextHasNoMargin` prop for opting into the new margin-free styles ([#43717](https://github.com/WordPress/gutenberg/pull/43717)).
- `ToggleControl`: Add `__nextHasNoMargin` prop for opting into the new margin-free styles ([#43717](https://github.com/WordPress/gutenberg/pull/43717)).
- `CheckboxControl`: Add `__nextHasNoMargin` prop for opting into the new margin-free styles ([#43720](https://github.com/WordPress/gutenberg/pull/43720)).
- `TextControl`, `TextareaControl`: Add `__nextHasNoMargin` prop for opting into the new margin-free styles ([#43782](https://github.com/WordPress/gutenberg/pull/43782)).
- `RangeControl`: Tweak dark gray marking color to be consistent with the grays in `@wordpress/base-styles` ([#43773](https://github.com/WordPress/gutenberg/pull/43773)).
- `UnitControl`: Tweak unit dropdown color to be consistent with the grays in `@wordpress/base-styles` ([#43773](https://github.com/WordPress/gutenberg/pull/43773)).
- `CardHeader`, `CardBody`, `CardFooter`: Tweak `isShady` background colors to be consistent with the grays in `@wordpress/base-styles` ([#43719](https://github.com/WordPress/gutenberg/pull/43719)).
- `InputControl`, `SelectControl`: Tweak `disabled` colors to be consistent with the grays in `@wordpress/base-styles` ([#43719](https://github.com/WordPress/gutenberg/pull/43719)).
- `Popover`: stabilize `__unstableShift` to `shift` ([#43845](https://github.com/WordPress/gutenberg/pull/43845)).

### Internal

- Remove unused `normalizeArrowKey` utility function ([#43640](https://github.com/WordPress/gutenberg/pull/43640/)).
- `ToggleGroupControl`: Rename `__experimentalIsIconGroup` prop to `__experimentalIsBorderless` ([#43771](https://github.com/WordPress/gutenberg/pull/43771/)).
- Refactor `FocalPointPicker` to function component ([#39168](https://github.com/WordPress/gutenberg/pull/39168)).
- `Guide`: use `code` instead of `keyCode` for keyboard events ([#43604](https://github.com/WordPress/gutenberg/pull/43604/)).
- `ToggleControl`: Convert to TypeScript and streamline CSS ([#43717](https://github.com/WordPress/gutenberg/pull/43717)).
- `ToggleControl`: Convert to TypeScript and streamline CSS ([#43717](https://github.com/WordPress/gutenberg/pull/43717)).
- `Navigation`: use `code` instead of `keyCode` for keyboard events ([#43644](https://github.com/WordPress/gutenberg/pull/43644/)).
- `ComboboxControl`: Add unit tests ([#42403](https://github.com/WordPress/gutenberg/pull/42403)).
- `NavigableContainer`: use `code` instead of `keyCode` for keyboard events, rewrite tests using RTL and `user-event` ([#43606](https://github.com/WordPress/gutenberg/pull/43606/)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const BorderBoxControlSplitControls = (
placement: popoverPlacement,
offset: popoverOffset,
anchorRef: containerRef,
__unstableShift: true,
shift: true,
}
: undefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const BorderBoxControl = (
placement: popoverPlacement,
offset: popoverOffset,
anchorRef: containerRef,
__unstableShift: true,
shift: true,
}
: undefined;

Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/color-palette/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export function CustomColorPickerDropdown( {
} ) {
const popoverProps = useMemo(
() => ( {
__unstableShift: true,
shift: true,
...( isRenderedInSidebar
? {
// When in the sidebar: open to the left (stacking),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ exports[`ColorPalette Dropdown should render it correctly 1`] = `
contentClassName="components-color-palette__custom-color-dropdown-content"
popoverProps={
Object {
"__unstableShift": true,
"offset": 8,
"placement": "bottom",
"shift": true,
}
}
renderContent={[Function]}
Expand Down Expand Up @@ -744,9 +744,9 @@ exports[`ColorPalette should render a dynamic toolbar of colors 1`] = `
contentClassName="components-color-palette__custom-color-dropdown-content"
popoverProps={
Object {
"__unstableShift": true,
"offset": 8,
"placement": "bottom",
"shift": true,
}
}
renderContent={[Function]}
Expand Down
8 changes: 8 additions & 0 deletions packages/components/src/popover/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ Adjusts the height of the `Popover` to prevent overflow.
- Required: No
- Default: `true`

### shift

Enables the `Popover` to shift in order to stay in view when meeting the viewport edges.

- Type: `Boolean`
- Required: No
- Default: `false`

### offset

The distance (in pixels) between the anchor and popover.
Expand Down
21 changes: 17 additions & 4 deletions packages/components/src/popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import classnames from 'classnames';
import {
useFloating,
flip as flipMiddleware,
shift,
shift as shiftMiddleware,
autoUpdate,
arrow,
offset as offsetMiddleware,
Expand Down Expand Up @@ -162,7 +162,8 @@ const Popover = (
__unstableSlotName = SLOT_NAME,
flip = true,
resize = true,
__unstableShift = false,
shift = false,
__unstableShift,
__unstableForcePosition,
...contentProps
},
Expand All @@ -188,6 +189,18 @@ const Popover = (
resize = ! __unstableForcePosition;
}

let shouldShift = shift;
if ( __unstableShift !== undefined ) {
deprecated( '`__unstableShift` prop in Popover component', {
since: '6.1',
version: '6.3',
alternative: '`shift` prop`',
} );

// Back-compat.
shouldShift = __unstableShift;
}

const arrowRef = useRef( null );

const [ fallbackReferenceElement, setFallbackReferenceElement ] =
Expand Down Expand Up @@ -262,8 +275,8 @@ const Popover = (
},
} )
: undefined,
__unstableShift
? shift( {
shouldShift
? shiftMiddleware( {
crossAxis: true,
limiter: limitShift(),
padding: 1, // Necessary to avoid flickering at the edge of the viewport.
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/popover/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default {
__unstableSlotName: { control: { type: null } },
resize: { control: { type: 'boolean' } },
flip: { control: { type: 'boolean' } },
__unstableShift: { control: { type: 'boolean' } },
shift: { control: { type: 'boolean' } },
},
};

Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/tooltip/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const addPopoverToGrandchildren = ( {
animate={ false }
offset={ offset }
anchorRef={ anchorRef }
__unstableShift
shift
>
{ text }
<Shortcut
Expand Down
2 changes: 1 addition & 1 deletion packages/format-library/src/link/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ function InlineLinkUI( {
focusOnMount={ focusOnMount.current }
onClose={ stopAddingLink }
position="bottom center"
__unstableShift
shift
>
<LinkControl
key={ forceRemountKey }
Expand Down
2 changes: 1 addition & 1 deletion packages/widgets/src/blocks/legacy-widget/edit/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default function Form( {
offset={ 32 }
resize={ false }
flip={ false }
__unstableShift
shift
>
<div
ref={ ref }
Expand Down