Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): style the new chat search clear button

Yudhi Armyndharisa76dfe563ba3
diff --git a/dashboard/src/pages/Chats.css b/dashboard/src/pages/Chats.css
index 08a849cb8..6c20aed83 100644
--- a/dashboard/src/pages/Chats.css
+++ b/dashboard/src/pages/Chats.css
@@ -2154,6 +2154,34 @@
margin-inline: 1.25rem;
}
+/* The clear button at the end of a search field: a small icon button whose block margin keeps it inside the
+ height of the line, so the field does not grow when it appears. */
+.chats-page .search-clear {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 28px;
+ height: 28px;
+ margin-block: -0.5rem;
+ padding: 0;
+ border: none;
+ border-radius: 6px;
+ background: transparent;
+ color: var(--text-muted);
+ cursor: pointer;
+ flex-shrink: 0;
+}
+
+.chats-page .search-clear:hover {
+ background: var(--border);
+ color: var(--text-primary);
+}
+
+.chats-page .search-clear:focus-visible {
+ outline: 2px solid var(--primary);
+ outline-offset: 1px;
+}
+
.chats-page .new-chat-hint {
margin-block: 0.375rem 0;
margin-inline: 1.25rem;
diff --git a/dashboard/src/pages/Chats.css.test.ts b/dashboard/src/pages/Chats.css.test.ts
new file mode 100644
index 000000000..864e30e33
--- /dev/null
+++ b/dashboard/src/pages/Chats.css.test.ts
@@ -0,0 +1,24 @@
+import { test } from 'node:test';
+import assert from 'node:assert/strict';
+import { readFileSync } from 'node:fs';
+import { fileURLToPath } from 'node:url';
+import { dirname, join } from 'node:path';
+
+// The clear button of the New chat panel's search field carried a class no stylesheet defined, so it rendered as
+// a native grey button that was taller than the text beside it and grew the field when a character was typed.
+
+const here = dirname(fileURLToPath(import.meta.url));
+const css = readFileSync(join(here, 'Chats.css'), 'utf8');
+const panel = readFileSync(join(here, '..', 'components', 'chats', 'NewChatPanel.tsx'), 'utf8');
+
+test('the new chat search clear button is a small icon button that does not grow the field', () => {
+ assert.match(panel, /className="search-clear"/, 'the panel no longer renders the button this rule styles');
+ const rule = /\.chats-page \.search-clear\s*\{([^}]*)\}/.exec(css);
+ assert.ok(rule, 'no style for the search clear button');
+ assert.match(rule[1], /border:\s*none/);
+ assert.match(rule[1], /background:\s*transparent/);
+ assert.match(rule[1], /width:\s*28px/);
+ assert.match(rule[1], /height:\s*28px/);
+ // Taller than the line of text it sits beside, so its block margin takes the difference back.
+ assert.match(rule[1], /margin-block:\s*-0\.5rem/);
+});