Skip to content

Commit e4c38af

Browse files
matt2eclaude
andcommitted
fix(messages): reveal the focused thumbnail inside the image strip
Tabbing through a posted image strip relies on native focus scrolling, and both engines refuse to scroll horizontally when the newly focused element is already partly visible. Blink sets the partial-visibility behaviour to no-scroll in Element::UpdateSelectionOnFocus, and WebKit keeps its 32px legacy horizontal visibility threshold on the focus reveal path; only scrollIntoView() opts out of either rule. A thumbnail whose far edge is clipped therefore takes focus without ever coming fully into view, and its focus ring is cut off. On the base commit this already happens for every strip width from 330 to 390px. The feed's scrollbar-gutter narrows the strip by 10px (Linux) or 11px (legacy-scrollbar macOS) under headless Chromium, which moved image-strip.spec.mjs's fixed 768px viewport into that window and made the Chromium shard of PR #451 fail at the last-tile visibility check (review comment P2). MessageRow.tsx now handles onFocus on the strip group (React's onFocus is the bubbling focusin, so one handler covers every tile) and nudges only the strip's own scrollLeft until the focused tile lies inside the strip's scroll-padding box. In Blink the native reveal runs first and the handler corrects the clipped case; in WebKit the handler runs first and the timer-driven native reveal then finds a fully visible element and does nothing. A strip-local adjustment is used instead of scrollIntoView so that overflow: hidden ancestors such as the thread container are never scrolled. Inline start and end are treated as left and right, matching the app's LTR layout. The feed's scrollbar-gutter CSS is unchanged. tests/browser/image-strip.spec.mjs now asserts the focused last tile lies inside the strip's scroll-padding box rather than the parent's bounding rect. This also catches the base commit's 1px short-of-max state at 398px, where the tile sat inside the border box but past the scroll-padding end with its ring clipped. Where the strip is too narrow to hold a tile plus both paddings (the 390px viewport once a gutter is reserved) the tile's far edge must sit exactly on the scroll-padding end. No assertion was loosened. Suites run (Hermit bin/pnpm): - biome check --error-on-warnings MessageRow.tsx image-strip.spec.mjs: clean - typecheck: clean - vitest src/features/messages/MessageRow.test.tsx: 71 passed - Playwright --project=chromium --project=webkit --no-deps image-strip.spec.mjs on macOS with legacy scrollbars (Chromium reserves an 11px gutter and reproduced the CI failure before the fix): 2 passed - Playwright --project=chromium --project=webkit --no-deps gifs, image-scroll, image-strip, message-management, messages, startup: 64 passed - Linux container (mcr.microsoft.com/playwright:v1.63.0-noble, CI config) --project=chromium and --project=webkit --no-deps image-strip.spec.mjs: 1 passed each. Swapping the unpatched MessageRow.tsx back into the container fails the Chromium run at the same assertion (now line 131, previously 113), so the CI failure is gone rather than moved. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Matt Toohey <[email protected]>
1 parent b68a91a commit e4c38af

2 files changed

Lines changed: 48 additions & 2 deletions

File tree

‎src/features/messages/MessageRow.tsx‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
useEffect,
1414
useCallback,
1515
useSyncExternalStore,
16+
type FocusEvent,
1617
type ReactNode,
1718
} from "react";
1819
import type { RelaySession } from "../relay/session";
@@ -88,6 +89,32 @@ export type MessageRowProps = {
8889
) => void;
8990
};
9091

92+
// Engines skip horizontal focus scrolling for a target that is already partly
93+
// visible: Blink sets the partial-visibility behaviour to no-scroll in
94+
// Element::UpdateSelectionOnFocus, and WebKit keeps its 32px legacy horizontal
95+
// visibility threshold for focus reveals. Only scrollIntoView() opts out of
96+
// both, so a thumbnail whose far edge is clipped keeps focus without ever
97+
// coming fully into view. Reveal it within the strip's scroll-padding.
98+
function revealFocusedThumbnail(event: FocusEvent<HTMLDivElement>) {
99+
const strip = event.currentTarget;
100+
const target = event.target;
101+
if (!(target instanceof HTMLElement) || target === strip) return;
102+
const style = getComputedStyle(strip);
103+
const bounds = strip.getBoundingClientRect();
104+
const rect = target.getBoundingClientRect();
105+
const start =
106+
bounds.left +
107+
strip.clientLeft +
108+
(Number.parseFloat(style.scrollPaddingInlineStart) || 0);
109+
const end =
110+
bounds.left +
111+
strip.clientLeft +
112+
strip.clientWidth -
113+
(Number.parseFloat(style.scrollPaddingInlineEnd) || 0);
114+
if (rect.right > end) strip.scrollLeft += rect.right - end;
115+
else if (rect.left < start) strip.scrollLeft -= start - rect.left;
116+
}
117+
91118
export const MessageRow = memo(function MessageRow({
92119
row,
93120
session,
@@ -550,6 +577,7 @@ export const MessageRow = memo(function MessageRow({
550577
className={styles.imageStrip}
551578
role="group"
552579
aria-label={`${group.length} ${group.length === 1 ? "image" : "images"}`}
580+
onFocus={revealFocusedThumbnail}
553581
>
554582
{items}
555583
</div>

‎tests/browser/image-strip.spec.mjs‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,30 @@ test("posted image strips keep counts visible and every image reachable beside d
102102
: "Tab",
103103
);
104104
await expect(links.last()).toBeFocused();
105+
// Neither engine scrolls horizontally on focus for a tile that is
106+
// already partly visible, so the last tile must be inside the strip's
107+
// scroll-padding box, not merely its border box: a reveal that stops
108+
// short of the strip's end lands the far edge in the padding where the
109+
// focus ring is clipped. A strip too narrow to hold a tile plus both
110+
// paddings (390px once a scrollbar gutter is reserved) can only honour
111+
// the far edge, which then has to sit exactly on the scroll-padding end.
105112
await expect
106113
.poll(() =>
107114
links.last().evaluate((el) => {
115+
const strip = el.parentElement;
116+
const style = getComputedStyle(strip);
108117
const a = el.getBoundingClientRect(),
109-
b = el.parentElement.getBoundingClientRect();
110-
return a.left >= b.left && a.right <= b.right;
118+
b = strip.getBoundingClientRect();
119+
const start =
120+
b.left +
121+
strip.clientLeft +
122+
(Number.parseFloat(style.scrollPaddingInlineStart) || 0);
123+
const end =
124+
b.left +
125+
strip.clientLeft +
126+
strip.clientWidth -
127+
(Number.parseFloat(style.scrollPaddingInlineEnd) || 0);
128+
return a.right <= end && a.left >= Math.min(start, end - a.width);
111129
}),
112130
)
113131
.toBe(true);

0 commit comments

Comments
 (0)