Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): draw form field focus in the focus ring colour

Yudhi Armyndharis5bd8608f7e4f
diff --git a/dashboard/src/components/FilterBuilder.css b/dashboard/src/components/FilterBuilder.css
index 3a0f858a5..9a7f1d6e2 100644
--- a/dashboard/src/components/FilterBuilder.css
+++ b/dashboard/src/components/FilterBuilder.css
@@ -53,6 +53,11 @@
width: 100%;
}
+/* The border above outweighs the global select:focus one, which also switches the outline off. */
+.filter-row select:focus {
+ border-color: var(--focus-ring);
+}
+
/* From 601px wide enough, with the padding above, for the longest field and operator label in every shipped
locale except the two or three over-long ones, which end in an ellipsis; the open list shows them whole. The
phone rule below replaces these bases. */
@@ -172,6 +177,11 @@
font-size: 0.8125rem;
}
+/* Same weight as `.modal-body input:focus`, which switches the outline off, and later, so its border would win. */
+.filter-text input[type='text']:focus {
+ border-color: var(--focus-ring);
+}
+
.filter-case {
display: inline-flex;
align-items: center;
@@ -268,6 +278,10 @@
border-radius: 6px;
}
+.chips-row .chips-text:focus {
+ border-color: var(--focus-ring);
+}
+
/* keep the yes/no select compact rather than filling the value column */
.filter-bool {
width: auto;
diff --git a/dashboard/src/components/GlobalSearch.css b/dashboard/src/components/GlobalSearch.css
index 523365448..7d6a66540 100644
--- a/dashboard/src/components/GlobalSearch.css
+++ b/dashboard/src/components/GlobalSearch.css
@@ -21,7 +21,7 @@
.global-search-input:focus {
outline: none;
- border-color: var(--primary);
+ border-color: var(--focus-ring);
box-shadow: 0 0 0 2px var(--primary-soft);
}
diff --git a/dashboard/src/focus-ring.test.ts b/dashboard/src/focus-ring.test.ts
index eb5405c6a..90db86e47 100644
--- a/dashboard/src/focus-ring.test.ts
+++ b/dashboard/src/focus-ring.test.ts
@@ -81,3 +81,70 @@ test('the meta line of a keyboard-focused search hit takes the secondary text co
assert.ok(rule, 'a focused hit leaves its meta line muted on the brand tint');
assert.match(rule.body, /(?:^|;)\s*color:\s*var\(--text-secondary\)/);
});
+
+// A field that switches its outline off shows focus as a border instead. In the brand fill (#25d366) that border is
+// 1.98:1 on white, under the 3:1 of SC 1.4.11, which is what the rings were before they took the token.
+const focusState = (s: string): boolean => /:focus(?:-visible|-within)?\b/.test(s.replace(/:not\([^)]*\)/g, ''));
+
+test('every border a focus state paints is drawn in the --focus-ring token', () => {
+ const painted = all
+ .filter(r => r.selectors.some(focusState))
+ .flatMap(r =>
+ [...r.body.matchAll(/(?:^|;)\s*(border(?:-(?:top|right|bottom|left))?(?:-color)?)\s*:\s*([^;]+)/g)].map(m => ({
+ at: `${r.file}: ${r.selectors.join(', ')}`,
+ prop: m[1],
+ value: m[2].trim(),
+ })),
+ )
+ .filter(({ prop, value }) => prop.endsWith('-color') || /var\(|#|rgb|hsl/.test(value));
+ assert.ok(painted.length >= 20, `only ${painted.length} focus borders seen`);
+ assert.deepEqual(
+ painted.filter(({ value }) => !/\bvar\(--focus-ring\)/.test(value)).map(({ at, value }) => `${at} => ${value}`),
+ [],
+ );
+});
+
+// The element a selector styles, its focus state and attribute filters aside: `input[type='text']:focus` and
+// `input:focus` style the same field.
+const element = (s: string): string =>
+ s
+ .replace(/:not\([^)]*\)/g, '')
+ .replace(/\[[^\]]*\]/g, '')
+ .replace(/:focus(?:-visible|-within)?/g, '')
+ .trim();
+
+// `outline: none` takes away the indicator the browser would draw, so something has to draw one in its place: the
+// same element in a focus state, or the box around it in :focus-within (a search box around its input).
+test('every outline switched off leaves a keyboard focus cue in the --focus-ring token', () => {
+ const cues = all.filter(r => /\bvar\(--focus-ring\)/.test(r.body)).flatMap(r => r.selectors.filter(focusState));
+ const offenders = all
+ .filter(r => /(?:^|;)\s*outline\s*:\s*(?:none|0)\b/.test(r.body))
+ .flatMap(r =>
+ r.selectors.filter(s => !/:not\(:focus-visible\)/.test(s)).map(s => ({ at: `${r.file}: ${s}`, el: element(s) })),
+ )
+ .filter(
+ ({ el }) =>
+ !cues.some(cue => element(cue) === el || (/:focus-within/.test(cue) && el.startsWith(`${element(cue)} `))),
+ );
+ assert.deepEqual(
+ offenders.map(({ at }) => at),
+ [],
+ );
+});
+
+// These fields repaint their own border after the shared `select:focus` and `.modal-body input:focus` rules, which
+// switch the outline off, so without a focus rule of their own a focused one looked like any other. A native checkbox
+// or radio shows no border at all, so the text field rules that reach it leave it only the ring.
+test('filter builder fields and native checkboxes draw their own focus cue', () => {
+ for (const [selector, cue] of [
+ ['.filter-row select:focus', /border-color:\s*var\(--focus-ring\)/],
+ [".filter-text input[type='text']:focus", /border-color:\s*var\(--focus-ring\)/],
+ ['.chips-row .chips-text:focus', /border-color:\s*var\(--focus-ring\)/],
+ ["input[type='checkbox']:not(.toggle-switch input):focus-visible", /outline:\s*2px solid var\(--focus-ring\)/],
+ ["input[type='radio']:not(.toggle-switch input):focus-visible", /outline:\s*2px solid var\(--focus-ring\)/],
+ ] as const) {
+ const rule = all.find(r => r.selectors.includes(selector));
+ assert.ok(rule, `no rule for ${selector}`);
+ assert.match(rule.body, cue, selector);
+ }
+});
diff --git a/dashboard/src/index.css b/dashboard/src/index.css
index 170936139..35d8e56bf 100644
--- a/dashboard/src/index.css
+++ b/dashboard/src/index.css
@@ -142,7 +142,7 @@ select:hover {
select:focus {
outline: none;
- border-color: var(--primary, #25d366);
+ border-color: var(--focus-ring);
box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.1);
}
@@ -257,7 +257,7 @@ select:disabled {
.modal-body input:focus {
outline: none;
- border-color: var(--primary, #25d366);
+ border-color: var(--focus-ring);
background: var(--bg-white, #fff);
box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.1);
}
@@ -277,6 +277,15 @@ select:disabled {
flex: none;
}
+/* The text field focus rules here and on the pages are written for `input` and also reach a native checkbox or radio:
+ they switch its outline off and draw a border it does not show, so a focused one showed nothing (in a dialog, on
+ the Message Tester). The ring comes back for keyboard focus. A switch draws its ring on the slider instead. */
+input[type='checkbox']:not(.toggle-switch input):focus-visible,
+input[type='radio']:not(.toggle-switch input):focus-visible {
+ outline: 2px solid var(--focus-ring);
+ outline-offset: 2px;
+}
+
.modal-footer {
display: flex;
justify-content: flex-end;
diff --git a/dashboard/src/pages/Chats.css b/dashboard/src/pages/Chats.css
index a81444f1f..f2f0baf78 100644
--- a/dashboard/src/pages/Chats.css
+++ b/dashboard/src/pages/Chats.css
@@ -61,7 +61,7 @@
}
.chats-page .session-selector:focus {
- border-color: var(--primary);
+ border-color: var(--focus-ring);
background-color: var(--bg-white);
box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.1);
}
@@ -126,7 +126,7 @@
}
.chats-page .chat-search-input:focus-within {
- border-color: var(--primary);
+ border-color: var(--focus-ring);
box-shadow: 0 0 0 3px var(--primary-soft);
}
@@ -826,7 +826,7 @@
}
.chats-page .message-text-input:focus {
- border-color: var(--primary);
+ border-color: var(--focus-ring);
background: var(--bg-white);
box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.1);
}
@@ -1801,7 +1801,7 @@
.chats-page .status-compose-modal textarea:focus,
.chats-page .status-compose-modal input:focus,
.chats-page .status-compose-modal select:focus {
- border-color: var(--primary);
+ border-color: var(--focus-ring);
background-color: var(--bg-white);
box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.1);
}
@@ -2311,7 +2311,7 @@
}
.chats-page .new-group-name:focus {
- border-color: var(--primary);
+ border-color: var(--focus-ring);
background: var(--bg-white);
}
@@ -2507,7 +2507,7 @@
.chats-page .group-info-field textarea:focus,
.chats-page .group-info-add input:focus,
.chats-page .chat-dialog-form input:focus {
- border-color: var(--primary);
+ border-color: var(--focus-ring);
background: var(--bg-white);
box-shadow: 0 0 0 3px var(--primary-soft);
}
diff --git a/dashboard/src/pages/Infrastructure.css b/dashboard/src/pages/Infrastructure.css
index 492fdec97..099e4e070 100644
--- a/dashboard/src/pages/Infrastructure.css
+++ b/dashboard/src/pages/Infrastructure.css
@@ -200,7 +200,7 @@
.infrastructure-page .form-group input:focus,
.infrastructure-page .form-group select:focus {
outline: none;
- border-color: var(--primary);
+ border-color: var(--focus-ring);
}
.infrastructure-page .form-group small {
diff --git a/dashboard/src/pages/Login.css b/dashboard/src/pages/Login.css
index 534283887..57649ec73 100644
--- a/dashboard/src/pages/Login.css
+++ b/dashboard/src/pages/Login.css
@@ -73,7 +73,7 @@
}
.login-container .login-language:focus-within {
- border-color: var(--primary);
+ border-color: var(--focus-ring);
box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.1);
}
@@ -112,7 +112,7 @@
.login-container .input-wrapper input:focus {
outline: none;
- border-color: var(--primary);
+ border-color: var(--focus-ring);
box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.1);
}
diff --git a/dashboard/src/pages/Logs.css b/dashboard/src/pages/Logs.css
index 8e22049d6..45799b75c 100644
--- a/dashboard/src/pages/Logs.css
+++ b/dashboard/src/pages/Logs.css
@@ -45,7 +45,7 @@
}
.logs-page .search-input:focus-within {
- border-color: var(--primary);
+ border-color: var(--focus-ring);
box-shadow: 0 0 0 3px var(--primary-soft);
}
diff --git a/dashboard/src/pages/MessageTester.css b/dashboard/src/pages/MessageTester.css
index 78a60cd97..164dc1fc1 100644
--- a/dashboard/src/pages/MessageTester.css
+++ b/dashboard/src/pages/MessageTester.css
@@ -67,7 +67,7 @@
.message-tester .form-group select:focus,
.message-tester .form-group textarea:focus {
outline: none;
- border-color: var(--primary);
+ border-color: var(--focus-ring);
}
.message-tester .form-group textarea {
diff --git a/dashboard/src/pages/NumberChecker.css b/dashboard/src/pages/NumberChecker.css
index 35e3474bb..fa890366c 100644
--- a/dashboard/src/pages/NumberChecker.css
+++ b/dashboard/src/pages/NumberChecker.css
@@ -179,7 +179,7 @@
.number-checker .nc-input:focus {
outline: none;
- border-color: var(--primary);
+ border-color: var(--focus-ring);
box-shadow: 0 0 0 3px var(--primary-soft);
}
@@ -199,7 +199,7 @@
.number-checker .nc-textarea:focus {
outline: none;
- border-color: var(--primary);
+ border-color: var(--focus-ring);
box-shadow: 0 0 0 3px var(--primary-soft);
}
diff --git a/dashboard/src/pages/Plugins.css b/dashboard/src/pages/Plugins.css
index 71f53176a..a975fc6ab 100644
--- a/dashboard/src/pages/Plugins.css
+++ b/dashboard/src/pages/Plugins.css
@@ -375,7 +375,7 @@
.plugins-page .config-form .form-group select:focus,
.plugins-page .config-form .form-group textarea:focus {
outline: none;
- border-color: var(--primary);
+ border-color: var(--focus-ring);
background-color: var(--bg-white);
box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.1);
}
@@ -1064,7 +1064,7 @@
}
.plugins-page .catalog-search:focus-within {
- border-color: var(--primary);
+ border-color: var(--focus-ring);
box-shadow: 0 0 0 3px var(--primary-soft);
}
diff --git a/dashboard/src/pages/Sessions.css b/dashboard/src/pages/Sessions.css
index 53dcc7b72..2f3fadc4b 100644
--- a/dashboard/src/pages/Sessions.css
+++ b/dashboard/src/pages/Sessions.css
@@ -47,7 +47,7 @@
}
.sessions-page .search-input:focus-within {
- border-color: var(--primary);
+ border-color: var(--focus-ring);
box-shadow: 0 0 0 3px var(--primary-soft);
}
@@ -387,7 +387,7 @@
.sessions-page .modal-body input:focus {
outline: none;
- border-color: var(--primary);
+ border-color: var(--focus-ring);
background: var(--bg-white);
box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.1);
}
diff --git a/dashboard/src/pages/Templates.css b/dashboard/src/pages/Templates.css
index d01fba465..a231afcdd 100644
--- a/dashboard/src/pages/Templates.css
+++ b/dashboard/src/pages/Templates.css
@@ -118,7 +118,7 @@
}
.templates-page .templates-search:focus-within {
- border-color: var(--primary);
+ border-color: var(--focus-ring);
box-shadow: 0 0 0 3px var(--primary-soft);
}
@@ -280,7 +280,7 @@
.templates-page .template-form textarea:focus,
.templates-page .placeholder-list input:focus {
outline: none;
- border-color: var(--primary);
+ border-color: var(--focus-ring);
background: var(--bg-white);
box-shadow: 0 0 0 3px var(--primary-soft);
}
diff --git a/dashboard/src/pages/Webhooks.css b/dashboard/src/pages/Webhooks.css
index f8ad27e11..f0b4ac6f0 100644
--- a/dashboard/src/pages/Webhooks.css
+++ b/dashboard/src/pages/Webhooks.css
@@ -313,12 +313,17 @@
outline: none;
}
-.webhooks-page .filter-badge-interactive:hover,
-.webhooks-page .filter-badge-interactive:focus-visible {
+.webhooks-page .filter-badge-interactive:hover {
border-color: var(--primary);
color: var(--text-primary);
}
+/* The badge takes no ring, so its border is the focus cue and has to be the contrast token, not the brand fill. */
+.webhooks-page .filter-badge-interactive:focus-visible {
+ border-color: var(--focus-ring);
+ color: var(--text-primary);
+}
+
/* Fixed-positioned (escapes the card's overflow:hidden); coordinates set inline from the badge rect. */
.webhooks-page .filter-popover {
position: fixed;