Skip to content

Commit 37c3297

Browse files
committed
Stabilize flip and resize
1 parent 7b9952a commit 37c3297

File tree

8 files changed

+45
-25
lines changed

8 files changed

+45
-25
lines changed

packages/block-editor/src/components/block-popover/inbetween.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ function BlockPopoverInbetween( {
186186
'block-editor-block-popover__inbetween',
187187
props.className
188188
) }
189-
__unstableResize={ false }
190-
__unstableFlip={ false }
189+
resize={ false }
190+
flip={ false }
191191
>
192192
<div style={ style }>{ children }</div>
193193
</Popover>

packages/block-editor/src/components/block-popover/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ function BlockPopover(
6868
__unstableSlotName={ __unstablePopoverSlot || null }
6969
// Observe movement for block animations (especially horizontal).
7070
__unstableObserveElement={ selectedElement }
71-
__unstableResize={ false }
72-
__unstableFlip={ false }
71+
resize={ false }
72+
flip={ false }
7373
__unstableShift
7474
{ ...props }
7575
className={ classnames(

packages/block-editor/src/components/block-tools/use-block-toolbar-popover-props.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import { __unstableUseBlockElement as useBlockElement } from '../block-list/use-
1515
// down the toolbar will stay on screen by adopting a sticky position at the
1616
// top of the viewport.
1717
const DEFAULT_PROPS = {
18-
__unstableResize: false,
19-
__unstableFlip: false,
18+
resize: false,
19+
flip: false,
2020
__unstableShift: true,
2121
};
2222

@@ -25,8 +25,8 @@ const DEFAULT_PROPS = {
2525
// obscured. The `flip` behavior is enabled, which positions the toolbar below
2626
// the block.
2727
const RESTRICTED_HEIGHT_PROPS = {
28-
__unstableResize: false,
29-
__unstableFlip: true,
28+
resize: false,
29+
flip: true,
3030
__unstableShift: false,
3131
};
3232

packages/components/CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
- `FormTokenField`: Refactor away from `_.difference()` ([#43224](https://github.com/WordPress/gutenberg/pull/43224/)).
2828
- `Autocomplete`: use `KeyboardEvent.code` instead of `KeyboardEvent.keyCode` ([#43432](https://github.com/WordPress/gutenberg/pull/43432/)).
2929
- `ConfirmDialog`: replace (almost) every usage of `fireEvent` with `@testing-library/user-event` ([#43429](https://github.com/WordPress/gutenberg/pull/43429/)).
30+
- `Popover`: Introduce new `flip` and `resize` props ([#43546](https://github.com/WordPress/gutenberg/pull/43546/)).
3031

3132
### Internal
3233

@@ -62,7 +63,7 @@
6263
### Experimental
6364

6465
- `FormTokenField`: add `__experimentalAutoSelectFirstMatch` prop to auto select the first matching suggestion on typing ([#42527](https://github.com/WordPress/gutenberg/pull/42527/)).
65-
- `Popover`: Refactor `__unstableForcePosition` to separate `__unstableFlip` and `__unstableResize` props ([#43546](https://github.com/WordPress/gutenberg/pull/43546/)).
66+
- `Popover`: Deprecate `__unstableForcePosition`, now replaced by new `flip` and `resize` props ([#43546](https://github.com/WordPress/gutenberg/pull/43546/)).
6667

6768
## 19.17.0 (2022-08-10)
6869

packages/components/src/popover/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,26 @@ Each of these base placements has an alignment in the form -start and -end. For
7171
- Required: No
7272
- Default: `"bottom-start"`
7373

74+
### flip
75+
76+
Specifies whether the `Popover` should flip across its axis if there isn't space for it in the normal placement.
77+
78+
When the using a 'top' placement, the `Popover` will switch to a 'bottom' placement. When using a 'left' placement, the popover will switch to a 'right' placement.
79+
80+
The `Popover` will retain its alignment of 'start' or 'end' when flipping.
81+
82+
- Type: `Boolean`
83+
- Required: No
84+
- Default: `true`
85+
86+
### resize
87+
88+
Adjusts the height of the `Popover` to prevent overflow.
89+
90+
- Type: `Boolean`
91+
- Required: No
92+
- Default: `true`
93+
7494
### offset
7595

7696
The distance (in pixels) between the anchor and popover.

packages/components/src/popover/index.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import classnames from 'classnames';
66
import {
77
useFloating,
8-
flip,
8+
flip as flipMiddleware,
99
shift,
1010
autoUpdate,
1111
arrow,
@@ -144,8 +144,8 @@ const Popover = (
144144
onFocusOutside,
145145
__unstableSlotName = SLOT_NAME,
146146
__unstableObserveElement,
147-
__unstableFlip = true,
148-
__unstableResize = true,
147+
flip = true,
148+
resize = true,
149149
__unstableShift = false,
150150
__unstableForcePosition = false,
151151
...contentProps
@@ -163,14 +163,13 @@ const Popover = (
163163
deprecated( '__unstableForcePosition prop in Popover component', {
164164
since: '6.1',
165165
version: '6.3',
166-
alternative:
167-
'`__unstableFlip={ false }` and `__unstableResize={ false }`',
166+
alternative: '`flip={ false }` and `resize={ false }`',
168167
} );
169168

170-
// Back-compat, set the `__unstableFlip` and `__unstableResize` props
169+
// Back-compat, set the `flip` and `resize` props
171170
// to `false` to replicate `__unstableForcePosition`.
172-
__unstableFlip = false;
173-
__unstableResize = false;
171+
flip = false;
172+
resize = false;
174173
}
175174

176175
const arrowRef = useRef( null );
@@ -249,8 +248,8 @@ const Popover = (
249248
crossAxis: frameOffsetRef.current[ crossAxis ],
250249
};
251250
} ),
252-
__unstableFlip ? flip() : undefined,
253-
__unstableResize
251+
flip ? flipMiddleware() : undefined,
252+
resize
254253
? size( {
255254
apply( sizeProps ) {
256255
const { availableHeight } = sizeProps;

packages/components/src/popover/stories/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ export default {
7474
},
7575
__unstableSlotName: { control: { type: null } },
7676
__unstableObserveElement: { control: { type: null } },
77-
__unstableResize: { control: { type: 'boolean' } },
78-
__unstableFlip: { control: { type: 'boolean' } },
77+
resize: { control: { type: 'boolean' } },
78+
flip: { control: { type: 'boolean' } },
7979
__unstableShift: { control: { type: 'boolean' } },
8080
},
8181
};
@@ -182,8 +182,8 @@ AllPlacements.args = {
182182
),
183183
noArrow: false,
184184
offset: 10,
185-
__unstableResize: false,
186-
__unstableFlip: false,
185+
resize: false,
186+
flip: false,
187187
};
188188

189189
export const DynamicHeight = ( { children, ...args } ) => {

packages/widgets/src/blocks/legacy-widget/edit/form.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ export default function Form( {
105105
focusOnMount={ false }
106106
placement="right"
107107
offset={ 32 }
108-
__unstableResize={ false }
109-
__unstableFlip={ false }
108+
resize={ false }
109+
flip={ false }
110110
__unstableShift
111111
>
112112
<div

0 commit comments

Comments
 (0)