swarm-ui: popover keeps its position object when a scroll moved nothing
This commit is contained in:
parent
afa9d861ba
commit
5c15580060
1 changed files with 7 additions and 4 deletions
|
|
@ -54,10 +54,13 @@ export function Popover({
|
||||||
const r = anchor.getBoundingClientRect();
|
const r = anchor.getBoundingClientRect();
|
||||||
const width = ref.current?.offsetWidth ?? 0;
|
const width = ref.current?.offsetWidth ?? 0;
|
||||||
const maxLeft = window.innerWidth - width - EDGE_PX;
|
const maxLeft = window.innerWidth - width - EDGE_PX;
|
||||||
setPos({
|
const top = r.bottom + GAP_PX;
|
||||||
top: r.bottom + GAP_PX,
|
const left = Math.max(EDGE_PX, Math.min(r.left, maxLeft));
|
||||||
left: Math.max(EDGE_PX, Math.min(r.left, maxLeft)),
|
// Scrolling anywhere (the streaming terminal included) calls this; keep
|
||||||
});
|
// the old object when nothing moved so the subtree does not re-render.
|
||||||
|
setPos((prev) =>
|
||||||
|
prev && prev.top === top && prev.left === left ? prev : { top, left },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
place();
|
place();
|
||||||
window.addEventListener("scroll", place, true);
|
window.addEventListener("scroll", place, true);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue