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

Fix misplaced Popover when using Floating UI (#566) #576

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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