Skip to content

Commit e592d2c

Browse files
committed
Fix misplaced when using Floating UI (#566)
1 parent 3808ce4 commit e592d2c

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/components/Popover/Popover.jsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export const Popover = React.forwardRef((props, ref) => {
1313
placement,
1414
children,
1515
portalId,
16+
position,
17+
x,
18+
y,
1619
...restProps
1720
} = props;
1821

@@ -26,6 +29,11 @@ export const Popover = React.forwardRef((props, ref) => {
2629
getRootAlignmentClassName(placement, styles),
2730
)}
2831
ref={ref}
32+
style={{
33+
left: x,
34+
position,
35+
top: y,
36+
}}
2937
>
3038
{children}
3139
<span className={styles.arrow} />
@@ -42,6 +50,9 @@ export const Popover = React.forwardRef((props, ref) => {
4250
Popover.defaultProps = {
4351
placement: 'bottom',
4452
portalId: null,
53+
position: null,
54+
x: null,
55+
y: null,
4556
};
4657

4758
Popover.propTypes = {
@@ -71,6 +82,18 @@ Popover.propTypes = {
7182
* If set, popover is rendered in the React Portal with that ID.
7283
*/
7384
portalId: PropTypes.string,
85+
/**
86+
* This sets the CSS property `position` of the popover. This is reserved for use with Floating UI.
87+
*/
88+
position: PropTypes.string,
89+
/**
90+
* This sets the CSS property `top` of the popover. This is reserved for use with Floating UI.
91+
*/
92+
x: PropTypes.string,
93+
/**
94+
* This sets the CSS property `left` of the popover. This is reserved for use with Floating UI.
95+
*/
96+
y: PropTypes.string,
7497
};
7598

7699
export const PopoverWithGlobalProps = withGlobalProps(Popover, 'Popover');

src/components/Popover/README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,9 @@ React.createElement(() => {
267267
<Popover
268268
id="my-advanced-popover"
269269
placement={finalPlacement}
270-
style={{
271-
position: strategy,
272-
top: y ? y : '',
273-
left: x ? x : '',
274-
}}
270+
position={strategy}
271+
x={x}
272+
y={y}
275273
ref={floating}
276274
>
277275
Auto-flipping Popover

0 commit comments

Comments
 (0)