fix(app): show the keyboard focus ring on icon buttons (#9745)

The shared icon button chrome set outlineWidth: 0, which overrides the
:focus-visible ring from public/index.html. Header and toolbar icon
buttons (sidebar toggle, workspace actions, Explorer toggle, new tab,
pane menu, diff toolbar) showed no indication of keyboard focus.

Drop the reset and draw the ring 2px inside the frame: the header title
row clips overflow, so an outset ring loses its top and bottom edges.
Pointer focus stays unringed through the existing *:focus rule.
This commit is contained in:
Junjie ZHANG authored and GitHub committed 2026-11-15 13:53:12 +00:00
1 parent c4ff5599c7
commit aa9984b899
2 files changed
+63 -6

No files matched your search

@@ -0,0 +1,56 @@
import { expect, type Locator, type Page } from "@playwright/test";
import { test } from "../support/fixtures";
import { gotoWorkspace } from "../support/helpers/launcher";
import { seedWorkspace } from "../support/helpers/seed-client";
import { waitForWorkspaceTabsVisible } from "../support/helpers/workspace-tabs";
const HEADER_ICON_BUTTONS = ["workspace-header-menu-trigger", "workspace-explorer-toggle"];
function visible(page: Page, testId: string): Locator {
return page.getByTestId(testId).filter({ visible: true }).first();
}
function matchesFocusVisible(target: Locator): Promise<boolean> {
return target.evaluate((el) => el.matches(":focus-visible"));
}
async function expectKeyboardFocusRing(page: Page, testId: string): Promise<void> {
const button = visible(page, testId);
// Chromium matches :focus-visible on a programmatic focus that follows keyboard input.
await page.keyboard.press("Shift");
await button.focus();
await expect(button).toBeFocused();
expect(await matchesFocusVisible(button)).toBe(true);
await expect(button).toHaveCSS("outline-style", "solid");
await expect(button).toHaveCSS("outline-width", "2px");
// Header rows clip overflow; an outset ring would lose its top and bottom edges.
await expect(button).toHaveCSS("outline-offset", "-2px");
}
async function expectNoPointerFocusRing(page: Page, testId: string): Promise<void> {
const button = visible(page, testId);
await button.blur();
// Toggle twice so the layout ends where it started.
await button.click();
await button.click();
await expect(button).toBeFocused();
expect(await matchesFocusVisible(button)).toBe(false);
await expect(button).toHaveCSS("outline-style", "none");
}
test.describe("Icon button focus ring", () => {
test("header icon buttons show the focus ring for keyboard focus only", async ({ page }) => {
await page.setViewportSize({ width: 1440, height: 900 });
const workspace = await seedWorkspace({ repoPrefix: "icon-button-focus-" });
try {
await gotoWorkspace(page, workspace.workspaceId);
await waitForWorkspaceTabsVisible(page);
for (const testId of HEADER_ICON_BUTTONS) {
await expectKeyboardFocusRing(page, testId);
}
await expectNoPointerFocusRing(page, "workspace-explorer-toggle");
} finally {
await workspace.cleanup();
}
});
});
@@ -126,6 +126,10 @@ export function smallIconButtonChromeFrameSize(compact = false): number {
return ICON_BUTTON_SIZES.small[controlSizingForLayout(compact)];
}
// Icon buttons sit in header and toolbar rows that clip overflow, so the keyboard focus ring
// from public/index.html is drawn inside the frame instead of around it.
const FOCUS_RING_INSET = -2;
const styles = StyleSheet.create((theme) => ({
large: {
width: bySizing(ICON_BUTTON_SIZES.large),
@@ -135,8 +139,7 @@ const styles = StyleSheet.create((theme) => ({
alignItems: "center",
justifyContent: "center",
flexShrink: 0,
outlineWidth: 0,
outlineColor: "transparent",
outlineOffset: FOCUS_RING_INSET,
},
small: {
width: ICON_BUTTON_SIZES.small.pointer,
@@ -146,8 +149,7 @@ const styles = StyleSheet.create((theme) => ({
alignItems: "center",
justifyContent: "center",
flexShrink: 0,
outlineWidth: 0,
outlineColor: "transparent",
outlineOffset: FOCUS_RING_INSET,
},
smallTouch: {
width: ICON_BUTTON_SIZES.small.touch,
@@ -157,8 +159,7 @@ const styles = StyleSheet.create((theme) => ({
alignItems: "center",
justifyContent: "center",
flexShrink: 0,
outlineWidth: 0,
outlineColor: "transparent",
outlineOffset: FOCUS_RING_INSET,
},
round: {
borderRadius: theme.borderRadius.full,