I recreated popover in the codesandbox here, follow the documentation code, the popover show up, but after scroll, the pointer does not align with the button anymore, I tried to pass container prop, but still not working. How can I solve this?
Steps to reproduce the behavior:

codesandbox
App.js
import "./styles.css";
import {
Popover,
OverlayTrigger,
Button,
ButtonToolbar
} from "react-bootstrap";
import React from "react";
import "bootstrap/dist/css/bootstrap.css";
const popoverBottom = (
<Popover id="popover-positioned-scrolling-bottom" title="Popover bottom">
<strong>Holy guacamole!</strong> Check this info.
</Popover>
);
const popoverRight = (
<Popover id="popover-positioned-scrolling-right" title="Popover right">
<strong>Holy guacamole!</strong> Check this info.
</Popover>
);
export default class Positioner extends React.Component {
render() {
return (
<div className="bs-example-popover-scroll">
<ButtonToolbar style={{ padding: "100px 0" }}>
<OverlayTrigger
container={this}
trigger="click"
placement="bottom"
overlay={popoverBottom}
>
<Button>Bottom guacamole!</Button>
</OverlayTrigger>
<OverlayTrigger
container={this}
trigger="click"
placement="right"
overlay={popoverRight}
>
<Button>Right guacamole!</Button>
</OverlayTrigger>
</ButtonToolbar>
</div>
);
}
}
index.js
import { StrictMode } from "react";
import ReactDOM from "react-dom";
import "bootstrap/dist/css/bootstrap.css";
import App from "./App";
const rootElement = document.getElementById("root");
ReactDOM.render(
<StrictMode>
<App />
</StrictMode>,
rootElement
);
styles.css
.App {
font-family: sans-serif;
text-align: center;
}
.bs-example-popover-scroll {
background: grey;
padding: 20px;
height: 200px;
overflow: scroll;
border: 1px solid black;
}
A popover should stay with a button element instead of scrolling container. A clear and concise description of what you expected to happen.

Your code is right. Since popover is an absolute div, it is positioned relative to the parent element with position relative. since you have not mentioned parent div(.bs-example-popover-scroll) as relative, the popover is positioned with respect to the document so it doesn't adjust as per scroll.
just add position relative to div.bs-example-popover-scroll and it work
modified code sandbox example
App.js
import "./styles.css";
import {
Popover,
OverlayTrigger,
Button,
ButtonToolbar
} from "react-bootstrap";
import React from "react";
import "bootstrap/dist/css/bootstrap.css";
const popoverBottom = (
<Popover id="popover-positioned-scrolling-bottom" title="Popover bottom">
<strong>Holy guacamole!</strong> Check this info.
</Popover>
);
const popoverRight = (
<Popover id="popover-positioned-scrolling-right" title="Popover right">
<strong>Holy guacamole!</strong> Check this info.
</Popover>
);
export default class Positioner extends React.Component {
render() {
return (
<div
className="bs-example-popover-scroll"
style={{ position: "relative" }}
>
<ButtonToolbar style={{ padding: "100px 0" }}>
<OverlayTrigger
container={this}
trigger="click"
placement="bottom"
overlay={popoverBottom}
>
<Button>Bottom guacamole!</Button>
</OverlayTrigger>
<OverlayTrigger
container={this}
trigger="click"
placement="right"
overlay={popoverRight}
>
<Button>Right guacamole!</Button>
</OverlayTrigger>
</ButtonToolbar>
</div>
);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With