Skip to content

Commit

Permalink
Fix misplaced when using Floating UI (#566)
Browse files Browse the repository at this point in the history
  • Loading branch information
atmelmicro committed Nov 19, 2024
1 parent 3808ce4 commit e592d2c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
23 changes: 23 additions & 0 deletions src/components/Popover/Popover.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export const Popover = React.forwardRef((props, ref) => {
placement,
children,
portalId,
position,
x,
y,
...restProps
} = props;

Expand All @@ -26,6 +29,11 @@ export const Popover = React.forwardRef((props, ref) => {
getRootAlignmentClassName(placement, styles),
)}
ref={ref}
style={{
left: x,
position,
top: y,
}}
>
{children}
<span className={styles.arrow} />
Expand All @@ -42,6 +50,9 @@ export const Popover = React.forwardRef((props, ref) => {
Popover.defaultProps = {
placement: 'bottom',
portalId: null,
position: null,
x: null,
y: null,
};

Popover.propTypes = {
Expand Down Expand Up @@ -71,6 +82,18 @@ Popover.propTypes = {
* If set, popover is rendered in the React Portal with that ID.
*/
portalId: PropTypes.string,
/**
* This sets the CSS property `position` of the popover. This is reserved for use with Floating UI.
*/
position: PropTypes.string,
/**
* This sets the CSS property `top` of the popover. This is reserved for use with Floating UI.
*/
x: PropTypes.string,
/**
* This sets the CSS property `left` of the popover. This is reserved for use with Floating UI.
*/
y: PropTypes.string,
};

export const PopoverWithGlobalProps = withGlobalProps(Popover, 'Popover');
Expand Down
8 changes: 3 additions & 5 deletions src/components/Popover/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,9 @@ React.createElement(() => {
<Popover
id="my-advanced-popover"
placement={finalPlacement}
style={{
position: strategy,
top: y ? y : '',
left: x ? x : '',
}}
position={strategy}
x={x}
y={y}
ref={floating}
>
Auto-flipping Popover
Expand Down

0 comments on commit e592d2c

Please sign in to comment.