Skip to content

Commit 0f6e822

Browse files
committed
fix(web): quote comment box stays in view for long code lines
The comment box for a new quote anchors to the last line rect of the quoted text. In a code block with lines wider than the pane, that rect is a narrow line-end rect far past the window edge, and Base UI keeps the popup attached to it, so the box opened off-screen. Pass `sticky` to the comment popup so it shifts into the window, and forward `sticky` through `PopoverPopup`.
1 parent 9d68e1e commit 0f6e822

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎apps/web/src/components/chat/AssistantCitationChip.browser.test.tsx‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,25 @@ describe("citation comment source disappearance", () => {
152152
expect(textarea()).toBeNull();
153153
});
154154
});
155+
156+
describe("citation comment popup placement", () => {
157+
it("opens inside the window when the cited line ends in a code block's horizontal overflow", async () => {
158+
const pre = document.createElement("pre");
159+
pre.style.cssText = "width: 120px; overflow-x: auto; white-space: pre; margin: 0";
160+
pre.textContent = `${"x".repeat(400)}\ny`;
161+
document.body.append(pre);
162+
const range = document.createRange();
163+
range.setStart(pre.firstChild!, 0);
164+
range.setEnd(pre.firstChild!, 401);
165+
sourceAnchor = { source: pre, range, viewport: document.body } as AssistantCitationSourceAnchor;
166+
// The anchor is the selection's last rect: a narrow line-end rect past the window edge.
167+
const rects = range.getClientRects();
168+
expect(rects.item(rects.length - 1)!.left).toBeGreaterThan(window.innerWidth);
169+
170+
await mount();
171+
172+
const popup = document.querySelector('[data-slot="popover-popup"]')!.getBoundingClientRect();
173+
expect(popup.left).toBeGreaterThanOrEqual(0);
174+
expect(popup.right).toBeLessThanOrEqual(window.innerWidth);
175+
});
176+
});

‎apps/web/src/components/chat/AssistantCitationChip.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ export function AssistantCitationChip({
175175
{...composerFloatingLayerProps}
176176
side={activeSourceAnchor ? "bottom" : "top"}
177177
align="end"
178+
// The anchor is the quote's last line rect, which can lie past the window edge
179+
// inside a code block's horizontal overflow. Without sticky, Base UI keeps the
180+
// popup attached to that rect instead of shifting it into view.
181+
sticky
178182
anchor={popupAnchor}
179183
initialFocus={() => {
180184
commentInputRef.current?.focus({ preventScroll: true });

‎apps/web/src/components/ui/popover.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function PopoverPopup({
4040
sideOffset = 4,
4141
alignOffset = 0,
4242
collisionAvoidance,
43+
sticky,
4344
tooltipStyle = false,
4445
keepMounted = false,
4546
anchor,
@@ -53,6 +54,7 @@ function PopoverPopup({
5354
sideOffset?: PopoverPrimitive.Positioner.Props["sideOffset"];
5455
alignOffset?: PopoverPrimitive.Positioner.Props["alignOffset"];
5556
collisionAvoidance?: PopoverPrimitive.Positioner.Props["collisionAvoidance"];
57+
sticky?: PopoverPrimitive.Positioner.Props["sticky"];
5658
tooltipStyle?: boolean;
5759
keepMounted?: PopoverPrimitive.Portal.Props["keepMounted"];
5860
anchor?: PopoverPrimitive.Positioner.Props["anchor"];
@@ -78,6 +80,7 @@ function PopoverPopup({
7880
alignOffset={alignOffset}
7981
anchor={anchor}
8082
collisionAvoidance={collisionAvoidance}
83+
sticky={sticky}
8184
collisionPadding={variant === "panel" ? 0 : undefined}
8285
className={cn(
8386
"h-(--positioner-height) w-(--positioner-width) max-w-(--available-width) transition-transform data-instant:transition-none",

0 commit comments

Comments
 (0)