Skip to content

Commit 108503f

Browse files
authored
feat(Popover): update default flip behavior and width (#8191)
* feat(Popover): update default flip behavior and width * fix flip positions for diagonals * revert default for autoWidth for now * remove old comment
1 parent dcdcfd2 commit 108503f

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

packages/react-core/src/components/Popover/Popover.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,20 @@ export const Popover: React.FunctionComponent<PopoverProps> = ({
260260
closeBtnAriaLabel = 'Close',
261261
showClose = true,
262262
distance = 25,
263-
// For every initial starting position, there are 3 escape positions
264-
flipBehavior = ['top', 'right', 'bottom', 'left', 'top', 'right', 'bottom'],
263+
flipBehavior = [
264+
'top',
265+
'bottom',
266+
'left',
267+
'right',
268+
'top-start',
269+
'top-end',
270+
'bottom-start',
271+
'bottom-end',
272+
'left-start',
273+
'left-end',
274+
'right-start',
275+
'right-end'
276+
],
265277
animationDuration = 300,
266278
id,
267279
withFocusTrap: propWithFocusTrap,

packages/react-core/src/helpers/Popper/Popper.tsx

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,45 @@
11
import * as React from 'react';
22
import * as ReactDOM from 'react-dom';
33
import { usePopper } from './thirdparty/react-popper/usePopper';
4-
import { Placement, BasePlacement, Modifier } from './thirdparty/popper-core';
4+
import { Placement, Modifier } from './thirdparty/popper-core';
55
import { css } from '@patternfly/react-styles';
66
import { FindRefWrapper } from './FindRefWrapper';
77
import '@patternfly/react-styles/css/components/Popper/Popper.css';
88

9-
const hash = { left: 'right', right: 'left', bottom: 'top', top: 'bottom' };
9+
const hash = {
10+
left: 'right',
11+
right: 'left',
12+
bottom: 'top',
13+
top: 'bottom',
14+
'top-start': 'bottom-end',
15+
'top-end': 'bottom-start',
16+
'bottom-start': 'top-end',
17+
'bottom-end': 'top-start',
18+
'left-start': 'right-end',
19+
'left-end': 'right-start',
20+
'right-start': 'left-end',
21+
'right-end': 'left-start'
22+
};
1023

1124
const getOppositePlacement = (placement: Placement): any =>
1225
placement.replace(
13-
/left|right|bottom|top/g,
14-
(matched: string) => hash[matched as 'left' | 'right' | 'bottom' | 'top'] as BasePlacement
26+
/left|right|bottom|top|top-start|top-end|bottom-start|bottom-end|right-start|right-end|left-start|left-end/g,
27+
(matched: string) =>
28+
hash[
29+
matched as
30+
| 'left'
31+
| 'right'
32+
| 'bottom'
33+
| 'top'
34+
| 'top-start'
35+
| 'top-end'
36+
| 'bottom-start'
37+
| 'bottom-end'
38+
| 'right-start'
39+
| 'right-end'
40+
| 'left-start'
41+
| 'left-end'
42+
] as Placement
1543
);
1644

1745
/** @deprecated Please use the menuAppendTo prop directly from within the PF component which uses it. */

0 commit comments

Comments
 (0)