Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): ring chat menu entries and search hits on focus

Yudhi Armyndharis85e6cdb0edd0
diff --git a/dashboard/src/components/GlobalSearch.css b/dashboard/src/components/GlobalSearch.css
index 0bda4bbf0..f8849786a 100644
--- a/dashboard/src/components/GlobalSearch.css
+++ b/dashboard/src/components/GlobalSearch.css
@@ -74,10 +74,14 @@
color: var(--text-primary);
}
-.global-search-hit:hover,
-.global-search-hit:focus-visible {
+.global-search-hit:hover {
background: var(--bg-light);
- outline: none;
+}
+
+.global-search-hit:focus-visible {
+ background: var(--primary-soft);
+ outline: 2px solid var(--primary);
+ outline-offset: -2px;
}
.global-search-hit:last-child {
diff --git a/dashboard/src/focus-ring.test.ts b/dashboard/src/focus-ring.test.ts
new file mode 100644
index 000000000..7d6d53855
--- /dev/null
+++ b/dashboard/src/focus-ring.test.ts
@@ -0,0 +1,57 @@
+import { test } from 'node:test';
+import assert from 'node:assert/strict';
+import { readFileSync, readdirSync } from 'node:fs';
+import { fileURLToPath } from 'node:url';
+import { dirname, join } from 'node:path';
+
+// Keyboard focus has to stay visible. A menu entry or search hit that answers :focus-visible with only
+// a one-step background change (1.05:1 on white) gives no cue where focus is, so the rule has to draw
+// a ring; `outline: none` there removes the only indicator the browser would have drawn.
+
+const SRC = dirname(fileURLToPath(import.meta.url));
+
+interface Rule {
+ file: string;
+ selectors: string[];
+ body: string;
+}
+
+function cssFiles(dir = SRC): string[] {
+ return readdirSync(dir, { withFileTypes: true }).flatMap(entry => {
+ const full = join(dir, entry.name);
+ if (entry.isDirectory()) return cssFiles(full);
+ return entry.name.endsWith('.css') ? [full.slice(SRC.length + 1)] : [];
+ });
+}
+
+function rules(file: string): Rule[] {
+ const css = readFileSync(join(SRC, file), 'utf8').replace(/\/\*[\s\S]*?\*\//g, '');
+ return [...css.matchAll(/([^{}]+)\{([^{}]*)\}/g)].map(m => ({
+ file,
+ selectors: m[1].split(',').map(s => s.trim()),
+ body: m[2],
+ }));
+}
+
+const all = cssFiles().flatMap(rules);
+// :not(:focus-visible) is the opposite state: a mouse click may drop the outline there.
+const focusVisible = (s: string): boolean => /:focus-visible/.test(s.replace(/:not\([^)]*\)/g, ''));
+
+test('no :focus-visible rule switches the outline off', () => {
+ const offenders = all
+ .filter(r => r.selectors.some(focusVisible) && /outline:\s*(?:none|0)\b/.test(r.body))
+ .map(r => `${r.file}: ${r.selectors.join(', ')}`);
+ assert.deepEqual(offenders, []);
+});
+
+test('chat menu entries and search hits draw a ring on keyboard focus', () => {
+ for (const selector of [
+ '.chats-page .chat-row-menu-popover button:focus-visible',
+ '.chats-page .room-menu-popover button:focus-visible',
+ '.global-search-hit:focus-visible',
+ ]) {
+ const rule = all.find(r => r.selectors.includes(selector));
+ assert.ok(rule, `no rule for ${selector}`);
+ assert.match(rule.body, /outline:\s*2px solid var\(--primary\)/, selector);
+ }
+});
diff --git a/dashboard/src/pages/Chats.css b/dashboard/src/pages/Chats.css
index 254c22c75..10610be6f 100644
--- a/dashboard/src/pages/Chats.css
+++ b/dashboard/src/pages/Chats.css
@@ -2095,11 +2095,16 @@
}
.chats-page .chat-row-menu-popover button:hover:not(:disabled),
+.chats-page .room-menu-popover button:hover:not(:disabled) {
+ background: var(--bg-light);
+}
+
+/* A one-step background change does not show keyboard focus, so the entry also gets a ring. */
.chats-page .chat-row-menu-popover button:focus-visible,
-.chats-page .room-menu-popover button:hover:not(:disabled),
.chats-page .room-menu-popover button:focus-visible {
- background: var(--bg-light);
- outline: none;
+ background: var(--primary-soft);
+ outline: 2px solid var(--primary);
+ outline-offset: -2px;
}
.chats-page .chat-row-menu-popover button svg,