Skip to content

Commit 5dcb59e

Browse files
maria-rcksclaude
andauthored
fix(ui): keep focus and selection borders visible across the app (#16675)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 08e18b7 commit 5dcb59e

79 files changed

Lines changed: 359 additions & 131 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/desktop/src/permissions/MacPermissionHelper.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ body { margin: 0; background: transparent; color: var(--text); font: 15px/22px -
5252
#panel { position: relative; margin: 2px; padding: 20px; height: 136px; border: 1px solid var(--line); border-radius: 24px; background: var(--base); }
5353
header { font-weight: 600; white-space: nowrap; }
5454
button { font: inherit; color: inherit; }
55-
button:focus-visible { outline: 2px solid #007aff; outline-offset: 3px; }
55+
button:focus-visible { outline: 2px solid #007aff; outline-offset: -2px; }
5656
#close { position: absolute; right: 8px; top: 6px; width: 22px; height: 22px; padding: 0; border: 0; border-radius: 50%; background: var(--base); font-size: 18px; cursor: pointer; opacity: 0; }
5757
#panel:hover #close, #close:focus-visible { opacity: 1; }
5858
#app { display: flex; align-items: center; gap: 12px; width: 100%; height: 52px; margin-top: 20px; padding: 8px 12px; border: 0; border-radius: 10px; background: var(--row); cursor: grab; text-align: left; font-size: 16px; font-weight: 600; }

‎apps/desktop/src/preview/Annotation.css‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,5 @@ input:focus-visible,
6464
select:focus-visible,
6565
textarea:focus-visible {
6666
outline: 2px solid color-mix(in srgb, var(--t3-ring) 72%, transparent);
67-
outline-offset: 1px;
67+
outline-offset: -2px;
6868
}

‎apps/desktop/src/preview/AnnotationStyles.generated.ts‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎apps/desktop/src/preview/PickPreload.ts‎

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,43 @@ function createBox(color: string, fill: string): HTMLDivElement {
316316
}
317317

318318
function positionBox(node: HTMLElement, rect: PreviewAnnotationRect): void {
319+
if (rect.width <= 0 || rect.height <= 0) {
320+
node.style.display = "none";
321+
return;
322+
}
319323
node.style.display = "block";
320324
node.style.transform = `translate(${rect.x}px, ${rect.y}px)`;
321325
node.style.width = `${rect.width}px`;
322326
node.style.height = `${rect.height}px`;
323327
}
324328

329+
/** Clamps a box to the viewport and clipping ancestors, so its border is never painted off-screen. */
330+
function visibleElementRect(element: Element): PreviewAnnotationRect {
331+
const rect = element.getBoundingClientRect();
332+
let left = Math.max(0, rect.left);
333+
let top = Math.max(0, rect.top);
334+
let right = Math.min(document.documentElement.clientWidth, rect.right);
335+
let bottom = Math.min(document.documentElement.clientHeight, rect.bottom);
336+
if (getComputedStyle(element).position !== "fixed") {
337+
for (let ancestor = element.parentElement; ancestor; ancestor = ancestor.parentElement) {
338+
if (ancestor === document.body || ancestor === document.documentElement) break;
339+
const style = getComputedStyle(ancestor);
340+
const bounds = ancestor.getBoundingClientRect();
341+
const clipLeft = bounds.left + ancestor.clientLeft;
342+
const clipTop = bounds.top + ancestor.clientTop;
343+
if (style.overflowX !== "visible") {
344+
left = Math.max(left, clipLeft);
345+
right = Math.min(right, clipLeft + ancestor.clientWidth);
346+
}
347+
if (style.overflowY !== "visible") {
348+
top = Math.max(top, clipTop);
349+
bottom = Math.min(bottom, clipTop + ancestor.clientHeight);
350+
}
351+
}
352+
}
353+
return { x: left, y: top, width: Math.max(0, right - left), height: Math.max(0, bottom - top) };
354+
}
355+
325356
function createLabel(): HTMLDivElement {
326357
const label = document.createElement("div");
327358
label.setAttribute(OVERLAY_ATTRIBUTE, "");
@@ -343,11 +374,15 @@ function updateSelectedVisual(target: SelectedElement): void {
343374
target.label.style.display = "none";
344375
return;
345376
}
346-
const rect = target.element.getBoundingClientRect();
347-
positionBox(target.outline, rectFromDomRect(rect));
377+
const rect = visibleElementRect(target.element);
378+
positionBox(target.outline, rect);
379+
if (rect.width === 0 || rect.height === 0) {
380+
target.label.style.display = "none";
381+
return;
382+
}
348383
target.label.textContent = describeRawElement(target.element);
349384
target.label.style.display = "block";
350-
target.label.style.transform = `translate(${Math.max(4, rect.left)}px, ${Math.max(4, rect.top - 22)}px)`;
385+
target.label.style.transform = `translate(${Math.max(4, rect.x)}px, ${Math.max(4, rect.y - 22)}px)`;
351386
}
352387

353388
function toStackFrame(frame: {
@@ -995,8 +1030,9 @@ function startAnnotation(sendEnabled: boolean): void {
9951030
const getAnnotationBounds = (): PreviewAnnotationRect | null =>
9961031
unionRects(
9971032
[
998-
...Array.from(selected.values(), (target) =>
999-
rectFromDomRect(target.element.getBoundingClientRect()),
1033+
// Follow the visible outline, so a clipped selection does not anchor the editor off-screen.
1034+
...Array.from(selected.values(), (target) => visibleElementRect(target.element)).filter(
1035+
(rect) => rect.width > 0 && rect.height > 0,
10001036
),
10011037
...regions.map((region) => region.rect),
10021038
...strokes.map((stroke) => stroke.bounds),
@@ -1108,6 +1144,8 @@ function startAnnotation(sendEnabled: boolean): void {
11081144
for (const target of selected.values()) updateSelectedVisual(target);
11091145
queueEditorLayout();
11101146
};
1147+
// A scrollbar appearing narrows the viewport without a window resize.
1148+
const rootResizeObserver = new ResizeObserver(repaint);
11111149

11121150
const removeTargetAtPoint = (x: number, y: number): boolean => {
11131151
for (const target of Array.from(selected.values()).toReversed()) {
@@ -1192,7 +1230,7 @@ function startAnnotation(sendEnabled: boolean): void {
11921230
}
11931231
if (tool === "select" && dragStart === null) {
11941232
const target = pickFromPoint(event.clientX, event.clientY);
1195-
if (target) positionBox(hoverOutline, rectFromDomRect(target.getBoundingClientRect()));
1233+
if (target) positionBox(hoverOutline, visibleElementRect(target));
11961234
else clearHoverOutline();
11971235
return;
11981236
}
@@ -1310,6 +1348,7 @@ function startAnnotation(sendEnabled: boolean): void {
13101348
const teardown = (notifyMain: boolean): void => {
13111349
if (finished) return;
13121350
finished = true;
1351+
rootResizeObserver.disconnect();
13131352
restoreStyles();
13141353
window.removeEventListener("pointermove", onPointerMove, true);
13151354
window.removeEventListener("pointerdown", onPointerDown, true);
@@ -1445,6 +1484,7 @@ function startAnnotation(sendEnabled: boolean): void {
14451484
ipcRenderer.on(CANCEL_PICK_CHANNEL, onCancel);
14461485
ipcRenderer.on(ANNOTATION_CAPTURED_CHANNEL, onCaptured);
14471486
document.documentElement.appendChild(host);
1487+
rootResizeObserver.observe(document.documentElement);
14481488
refreshToolButtons();
14491489
updateStatus();
14501490
activeSession = {

‎apps/server/src/htmlRender/HtmlRender.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,12 @@ describe("HtmlRender", () => {
244244
const htmlRender = yield* HtmlRender.HtmlRender;
245245
const preview = yield* htmlRender.preview({
246246
html: [
247-
'<!doctype html><html><head></head><body><div style="height:300px;background:var(--accent)"></div>',
247+
'<!doctype html><html><head></head><body><div id="page" tabindex="0" style="height:300px;background:var(--accent)"></div>',
248248
'<img src="/nonexistent/t3-missing.png" hidden>',
249249
"<script>",
250250
"const root = getComputedStyle(document.documentElement);",
251+
'const page = document.getElementById("page"); page.focus();',
252+
'const focus = getComputedStyle(page); console.log("focus", focus.outlineWidth, focus.outlineOffset, page.getBoundingClientRect().width, document.documentElement.scrollWidth);',
251253
'console.log("ready", 3); console.info(root.getPropertyValue("--font-sans"));',
252254
'console.warn(root.getPropertyValue("--background")); console.error("boom");',
253255
"</script>",
@@ -271,6 +273,7 @@ describe("HtmlRender", () => {
271273
expect(preview.consoleMessages).toEqual(
272274
expect.arrayContaining([
273275
{ level: "log", text: "ready 3" },
276+
{ level: "log", text: "focus 2px -2px 400 400" },
274277
{ level: "info", text: HTML_RENDER_MEASURE_FONTS.sans },
275278
{
276279
level: "warning",

‎apps/web/src/components/ContextChip.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { cn } from "~/lib/utils";
2323
* span with tabIndex for a tooltip) gets the focus outline.
2424
*/
2525
const contextChipVariants = cva(
26-
"inline-flex h-[1.41em] max-w-full items-center gap-[0.33em] rounded-[0.5em] border px-[0.5em] align-middle font-medium text-[0.86em] leading-none [&_svg]:block [&_svg]:size-[1.17em] [&_svg]:shrink-0 [&_svg]:self-center [button&,a&,[data-popup-open]&]:cursor-pointer [button&,a&]:transition-colors [button&,a&]:motion-reduce:transition-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-foreground disabled:cursor-default",
26+
"inline-flex h-[1.41em] max-w-full items-center gap-[0.33em] rounded-[0.5em] border px-[0.5em] align-middle font-medium text-[0.86em] leading-none [&_svg]:block [&_svg]:size-[1.17em] [&_svg]:shrink-0 [&_svg]:self-center [button&,a&,[data-popup-open]&]:cursor-pointer [button&,a&]:transition-colors [button&,a&]:motion-reduce:transition-none focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-foreground disabled:cursor-default",
2727
{
2828
defaultVariants: { kind: "neutral" },
2929
variants: {
@@ -117,7 +117,7 @@ function ContextChipLabel({ className, ...props }: React.ComponentProps<"span">)
117117
function ContextChipAction({ className, render, ...props }: useRender.ComponentProps<"button">) {
118118
const defaultProps = {
119119
className: cn(
120-
"ml-[0.17em] inline-flex size-[1.17em] shrink-0 cursor-pointer items-center justify-center rounded-sm text-current transition-colors hover:bg-(--context-chip-accent,var(--color-foreground))/17 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring motion-reduce:transition-none [&_svg]:size-[0.85em]",
120+
"ml-[0.17em] inline-flex size-[1.17em] shrink-0 cursor-pointer items-center justify-center rounded-sm text-current transition-colors hover:bg-(--context-chip-accent,var(--color-foreground))/17 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring motion-reduce:transition-none [&_svg]:size-[0.85em]",
121121
className,
122122
),
123123
"data-slot": "context-chip-action",

‎apps/web/src/components/GitActionsControl.tsx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -793,9 +793,9 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {
793793
value={option.value}
794794
className={cn(
795795
"relative flex cursor-pointer items-center gap-3 rounded-lg border px-3 py-3 text-left outline-none transition-[background-color,border-color,box-shadow]",
796-
"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",
796+
"focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",
797797
isSelected
798-
? "border-primary bg-background shadow-sm ring-2 ring-primary/35 dark:border-transparent dark:bg-primary/10 dark:shadow-none dark:ring-1 dark:ring-primary/30"
798+
? "border-primary bg-background shadow-sm ring-2 ring-inset ring-primary/35 dark:border-transparent dark:bg-primary/10 dark:shadow-none dark:ring-1 dark:ring-primary/30"
799799
: "border-border bg-background hover:border-foreground/20 hover:bg-muted/50 dark:border-transparent dark:bg-white/[0.035] dark:hover:bg-accent",
800800
)}
801801
>
@@ -817,7 +817,7 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {
817817
>
818818
Repository
819819
</label>
820-
<div className="flex items-stretch overflow-hidden rounded-md border border-input bg-background focus-within:outline-2 focus-within:-outline-offset-1 focus-within:outline-ring">
820+
<div className="flex items-stretch overflow-hidden rounded-md border border-input bg-background focus-within:outline-2 focus-within:-outline-offset-2 focus-within:outline-ring">
821821
<span className="flex shrink-0 items-center gap-1.5 border-r border-input bg-muted/50 px-2.5 font-mono text-xs text-muted-foreground">
822822
<currentPublishProvider.Icon className="size-3.5" />
823823
{publishHost}/
@@ -879,9 +879,9 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {
879879
value={option.value}
880880
className={cn(
881881
"relative flex cursor-pointer items-center gap-3 rounded-lg border px-3 py-2.5 text-left outline-none transition-[background-color,border-color,box-shadow]",
882-
"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",
882+
"focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",
883883
isSelected
884-
? "border-primary bg-background shadow-sm ring-2 ring-primary/35 dark:border-transparent dark:bg-primary/10 dark:shadow-none dark:ring-1 dark:ring-primary/30"
884+
? "border-primary bg-background shadow-sm ring-2 ring-inset ring-primary/35 dark:border-transparent dark:bg-primary/10 dark:shadow-none dark:ring-1 dark:ring-primary/30"
885885
: "border-border bg-background hover:border-foreground/20 hover:bg-muted/50 dark:border-transparent dark:bg-white/[0.035] dark:hover:bg-accent",
886886
)}
887887
>

‎apps/web/src/components/LegacySidebar.tsx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ const PROJECT_GROUPING_MODE_LABELS: Record<SidebarProjectGroupingMode, string> =
246246
separate: "Keep separate",
247247
};
248248
const SIDEBAR_ICON_ACTION_BUTTON_CLASS =
249-
"inline-flex h-6 min-w-6 cursor-pointer items-center justify-center rounded-md px-0.75 text-icon-muted hover:text-foreground focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-ring";
249+
"inline-flex h-6 min-w-6 cursor-pointer items-center justify-center rounded-md px-0.75 text-icon-muted hover:text-foreground focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring";
250250

251251
function SidebarThreadDetailPrewarmer({ threadRef }: { readonly threadRef: ScopedThreadRef }) {
252252
useEnvironmentThread(threadRef.environmentId, threadRef.threadId);
@@ -769,7 +769,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
769769
target="_blank"
770770
rel="noopener noreferrer"
771771
aria-label={prStatus.tooltip}
772-
className={`inline-flex items-center justify-center ${prStatus.colorClass} cursor-pointer rounded-sm outline-hidden focus-visible:ring-1 focus-visible:ring-ring`}
772+
className={`inline-flex items-center justify-center ${prStatus.colorClass} cursor-pointer rounded-sm outline-hidden focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring`}
773773
onPointerDown={(event) => event.stopPropagation()}
774774
onClick={handlePrClick}
775775
>
@@ -835,7 +835,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
835835
<button
836836
type="button"
837837
aria-label={`Open localhost:${discoveredPorts[0]?.port ?? ""}`}
838-
className="inline-flex cursor-pointer items-center justify-center text-success-foreground outline-hidden focus-visible:ring-1 focus-visible:ring-ring"
838+
className="inline-flex cursor-pointer items-center justify-center text-success-foreground outline-hidden focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring"
839839
onClick={handleOpenDiscoveredPort}
840840
/>
841841
}
@@ -880,7 +880,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
880880
data-thread-selection-safe
881881
data-testid={`thread-archive-confirm-${thread.id}`}
882882
aria-label={`Confirm archive ${thread.title}`}
883-
className="absolute top-1/2 right-1 inline-flex h-5 -translate-y-1/2 cursor-pointer items-center rounded-md bg-destructive/12 px-2 text-3xs font-medium text-destructive transition-colors hover:bg-destructive/18 focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-destructive/40"
883+
className="absolute top-1/2 right-1 inline-flex h-5 -translate-y-1/2 cursor-pointer items-center rounded-md bg-destructive/12 px-2 text-3xs font-medium text-destructive transition-colors hover:bg-destructive/18 focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-destructive/40"
884884
onPointerDown={stopPropagationOnPointerDown}
885885
onClick={handleConfirmArchiveClick}
886886
>
@@ -2955,7 +2955,7 @@ function SortableProjectItem({
29552955
}}
29562956
className={`group/menu-item relative rounded-md ${
29572957
isDragging ? "z-20 opacity-80" : ""
2958-
} ${isOver && !isDragging ? "ring-1 ring-primary/40" : ""}`}
2958+
} ${isOver && !isDragging ? "ring-1 ring-inset ring-primary/40" : ""}`}
29592959
data-sidebar="menu-item"
29602960
data-slot="sidebar-menu-item"
29612961
>

‎apps/web/src/components/RightPanelTabs.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
11931193
{renamingDevice === surface.id ? (
11941194
<input
11951195
aria-label="Device tab name"
1196-
className="w-24 min-w-0 rounded-sm bg-background px-1 outline-none ring-1 ring-ring"
1196+
className="w-24 min-w-0 rounded-sm bg-background px-1 outline-none ring-1 ring-inset ring-ring"
11971197
defaultValue={title}
11981198
ref={(element) => {
11991199
element?.focus();

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,7 +1763,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
17631763
type="button"
17641764
aria-label="Unpin thread"
17651765
onClick={handleUnpinClick}
1766-
className="group/unpin inline-flex cursor-pointer items-center rounded-sm text-muted-foreground/65 outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring"
1766+
className="group/unpin inline-flex cursor-pointer items-center rounded-sm text-muted-foreground/65 outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
17671767
/>
17681768
}
17691769
>
@@ -1876,7 +1876,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
18761876
type="button"
18771877
aria-label="Dismiss Woke notification"
18781878
onClick={handleAcknowledgeWokeClick}
1879-
className="inline-flex cursor-pointer items-center gap-1 rounded-sm text-xs font-medium text-warning-foreground outline-none hover:underline focus-visible:ring-2 focus-visible:ring-ring"
1879+
className="inline-flex cursor-pointer items-center gap-1 rounded-sm text-xs font-medium text-warning-foreground outline-none hover:underline focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
18801880
>
18811881
<AlarmClockIcon aria-hidden className="size-3" />
18821882
<span role="status">Woke</span>
@@ -2040,7 +2040,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
20402040
aria-label="Dismiss Woke notification"
20412041
onClick={handleAcknowledgeWokeClick}
20422042
className={cn(
2043-
"inline-flex cursor-pointer items-center gap-1 rounded-sm font-medium outline-none hover:underline focus-visible:ring-2 focus-visible:ring-ring",
2043+
"inline-flex cursor-pointer items-center gap-1 rounded-sm font-medium outline-none hover:underline focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",
20442044
topStatus.className,
20452045
)}
20462046
>

0 commit comments

Comments
 (0)