Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

♿ a11y: Let Dark Mode Honor Outline Utilities on Focus (#16861)

Marco Beretta6f746363754e
diff --git a/client/src/style.css b/client/src/style.css
index 0cc01220de..85ca06a666 100644
--- a/client/src/style.css
+++ b/client/src/style.css
@@ -1997,7 +1997,10 @@ html[data-input-modality='keyboard']
}
}
-.dark :focus-visible {
+/* A control that declares its own focus outline utility (`focus-visible:outline-hidden`,
+ * `focus-visible:outline-2 focus-visible:outline-focus-subtle`) keeps it: this rule is unlayered,
+ * so it would otherwise outrank every outline utility and repaint the global role over them. */
+.dark :focus-visible:not([class*='focus-visible:outline-'], [class*='focus:outline-']) {
outline: var(--theme-focus-ring-width, 2px) solid rgb(var(--focus-outline));
outline-offset: var(--theme-focus-ring-offset, 2px);
}
diff --git a/e2e/specs/mock/scenarios/focus-primitives.spec.ts b/e2e/specs/mock/scenarios/focus-primitives.spec.ts
new file mode 100644
index 0000000000..8cc889363b
--- /dev/null
+++ b/e2e/specs/mock/scenarios/focus-primitives.spec.ts
@@ -0,0 +1,149 @@
+import { expect, test } from '@playwright/test';
+import type { Page } from '@playwright/test';
+import { NEW_CHAT_PATH } from '../helpers';
+
+/**
+ * The primitives that draw their own keyboard ring (Tabs, Table rows, Dropdown and its menu items)
+ * name the `focus-control` role, which the bundled themes keep equal to the primary ink, and a
+ * control that declares an outline utility keeps it in dark mode instead of losing it to the global
+ * `.dark :focus-visible` rule.
+ */
+
+type Mode = 'light' | 'dark';
+
+type Check = 'role' | 'hidden' | 'utility' | 'global';
+
+const RING_CLASSES =
+ 'focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-focus-control';
+const HIDDEN_CLASSES =
+ 'focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-focus-control';
+const UTILITY_CLASSES =
+ 'focus-visible:outline-focus-subtle focus-visible:outline focus-visible:outline-2';
+
+const PROBE = 'focus-primitives-probe';
+
+async function openChat(page: Page, mode: Mode) {
+ await page.addInitScript((appearance) => {
+ localStorage.setItem('color-theme', appearance);
+ localStorage.removeItem('theme-colors');
+ localStorage.removeItem('theme-name');
+ localStorage.removeItem('theme-definition');
+ localStorage.removeItem('theme-source');
+ }, mode);
+ await page.goto(NEW_CHAT_PATH, { timeout: 15000 });
+ await expect(page.getByRole('textbox', { name: 'Message input' })).toBeVisible({
+ timeout: 30000,
+ });
+ await expect(page.locator('html')).toHaveClass(mode === 'dark' ? /\bdark\b/ : /\blight\b/);
+}
+
+/** Tabs onto a bare button carrying `classes` and reads the outline and ring it draws. */
+async function keyboardFocus(page: Page, classes: string) {
+ await page.evaluate(
+ ([id, className]) => {
+ const sentinel = document.createElement('span');
+ sentinel.tabIndex = -1;
+ const probe = document.createElement('button');
+ probe.id = id;
+ probe.className = className;
+ probe.textContent = 'Probe';
+ document.body.prepend(sentinel, probe);
+ sentinel.focus();
+ },
+ [PROBE, classes],
+ );
+ await page.keyboard.press('Tab');
+ const probe = page.locator(`#${PROBE}`);
+ await expect(probe).toBeFocused();
+ return probe.evaluate((node) => {
+ const style = getComputedStyle(node);
+ const root = getComputedStyle(document.documentElement);
+ return {
+ outlineStyle: style.outlineStyle,
+ outlineColor: style.outlineColor,
+ ring: style.getPropertyValue('--tw-ring-color').trim(),
+ focusControl: root.getPropertyValue('--focus-control').trim(),
+ textPrimary: root.getPropertyValue('--text-primary').trim(),
+ };
+ });
+}
+
+/** Each tag is written out whole: the runner finds a scenario by its literal tag. */
+const CASES: Array<{ title: string; mode: Mode; check: Check }> = [
+ {
+ title:
+ 'the ring role equals the primary ink in the default light theme @scenario:focus-primitives-role-default-light',
+ mode: 'light',
+ check: 'role',
+ },
+ {
+ title:
+ 'the ring role equals the primary ink in the default dark theme @scenario:focus-primitives-role-default-dark',
+ mode: 'dark',
+ check: 'role',
+ },
+ {
+ title:
+ 'an outline-hidden control draws no global outline in light @scenario:focus-primitives-outline-hidden-light',
+ mode: 'light',
+ check: 'hidden',
+ },
+ {
+ title:
+ 'an outline-hidden control draws no global outline in dark @scenario:focus-primitives-outline-hidden-dark',
+ mode: 'dark',
+ check: 'hidden',
+ },
+ {
+ title:
+ 'a control with its own outline utility keeps it in light @scenario:focus-primitives-outline-utility-light',
+ mode: 'light',
+ check: 'utility',
+ },
+ {
+ title:
+ 'a control with its own outline utility keeps it in dark @scenario:focus-primitives-outline-utility-dark',
+ mode: 'dark',
+ check: 'utility',
+ },
+ {
+ title:
+ 'a bare control keeps the global outline role in light @scenario:focus-primitives-global-outline-light',
+ mode: 'light',
+ check: 'global',
+ },
+ {
+ title:
+ 'a bare control keeps the global outline role in dark @scenario:focus-primitives-global-outline-dark',
+ mode: 'dark',
+ check: 'global',
+ },
+];
+
+test.describe('primitives focus ring', () => {
+ for (const { title, mode, check } of CASES) {
+ test(title, async ({ page }) => {
+ await openChat(page, mode);
+
+ if (check === 'role') {
+ const { focusControl, textPrimary } = await keyboardFocus(page, RING_CLASSES);
+ expect(focusControl).not.toBe('');
+ expect(focusControl).toBe(textPrimary);
+ return;
+ }
+ if (check === 'hidden') {
+ expect((await keyboardFocus(page, HIDDEN_CLASSES)).outlineStyle).toBe('none');
+ return;
+ }
+ if (check === 'utility') {
+ const { outlineStyle, outlineColor } = await keyboardFocus(page, UTILITY_CLASSES);
+ expect(outlineStyle).toBe('solid');
+ expect(outlineColor).toBe(mode === 'dark' ? 'rgb(89, 89, 89)' : 'rgb(153, 150, 150)');
+ return;
+ }
+ const { outlineStyle, outlineColor } = await keyboardFocus(page, '');
+ expect(outlineStyle).toBe('solid');
+ expect(outlineColor).toBe(mode === 'dark' ? 'rgb(255, 255, 255)' : 'rgb(0, 0, 0)');
+ });
+ }
+});
diff --git a/packages/client/src/theme/semanticTokens.spec.ts b/packages/client/src/theme/semanticTokens.spec.ts
index 58b9183eff..7b41b339b0 100644
--- a/packages/client/src/theme/semanticTokens.spec.ts
+++ b/packages/client/src/theme/semanticTokens.spec.ts
@@ -168,7 +168,11 @@ describe('shared field and dropdown interaction styles', () => {
const roleOutline =
':focus-visible \\{\\s*outline: var\\(--theme-focus-ring-width, 2px\\) solid rgb\\(var\\(--focus-outline\\)\\);\\s*outline-offset: var\\(--theme-focus-ring-offset, 2px\\);';
expect(appStyles).toMatch(new RegExp(`@layer base \\{\\s*${roleOutline}`));
- expect(appStyles).toMatch(new RegExp(`\\.dark ${roleOutline}`));
+ expect(appStyles).toMatch(
+ new RegExp(
+ `\\.dark ${roleOutline.replace(':focus-visible ', ":focus-visible:not\\(\\[class\\*='focus-visible:outline-'\\], \\[class\\*='focus:outline-'\\]\\) ")}`,
+ ),
+ );
expect(appStyles).not.toMatch(/textarea\s*\n\):hover,/);
});