Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): keep the phone drawer clear of its close button

Yudhi Armyndharis604fbf7c0377
diff --git a/dashboard/src/components/Layout.css b/dashboard/src/components/Layout.css
index 9fd9dd987..717d74449 100644
--- a/dashboard/src/components/Layout.css
+++ b/dashboard/src/components/Layout.css
@@ -353,7 +353,8 @@
padding: 0 1rem;
background: var(--bg-white);
border-bottom: 1px solid var(--border);
- z-index: 90;
+ /* Above the overlay (95) so the menu button, the close control while the drawer is open, is not dimmed. */
+ z-index: 96;
}
.mobile-menu-btn {
@@ -390,9 +391,20 @@
font-size: 1rem;
}
+ /* The drawer starts under the header (56px, as the header and the page scroller's padding) so it never covers the
+ menu button. */
.sidebar.mobile {
transform: translateX(-100%);
width: 280px;
+ top: 56px;
+ height: calc(100vh - 56px);
+ height: calc(100dvh - 56px);
+ }
+
+ /* The menu grows upward from the footer, so it gives up the header strip the drawer no longer spans. */
+ .sidebar.mobile .language-menu-list {
+ max-height: calc(100vh - 13rem - 56px);
+ max-height: calc(100dvh - 13rem - 56px);
}
/* The shadow belongs to the open drawer: on the closed one it would reach past the screen edge. */
diff --git a/dashboard/src/components/Layout.css.test.ts b/dashboard/src/components/Layout.css.test.ts
index a01405346..bf3f8fa41 100644
--- a/dashboard/src/components/Layout.css.test.ts
+++ b/dashboard/src/components/Layout.css.test.ts
@@ -113,6 +113,41 @@ test('the full-height sidebar and mobile scroller follow the dynamic viewport',
assert.deepEqual(valuesOf(scroller.body, 'min-height'), ['0']);
});
+// The header menu button turns into the close control while the drawer is open. A drawer that started at the top edge
+// sat over it (sidebar 100, header 90) and the tap landed on the drawer's logo. The drawer starts under the header, and
+// the header rises above the dimming overlay so the button stays visible and tappable.
+test('the phone drawer starts below the mobile header and the header stays above the overlay', () => {
+ const header = find('.mobile-header').find(r => r.media);
+ assert.ok(header, 'no mobile .mobile-header rule');
+ const headerHeight = decl(header.body, 'height');
+ assert.match(headerHeight ?? '', /^\d+px$/);
+
+ const drawer = find('.sidebar.mobile').find(r => r.media);
+ assert.ok(drawer, 'no mobile .sidebar.mobile rule');
+ assert.equal(decl(drawer.body, 'top'), headerHeight, 'the drawer starts above the bottom of the header');
+ assert.deepEqual(valuesOf(drawer.body, 'height'), [
+ `calc(100vh - ${headerHeight})`,
+ `calc(100dvh - ${headerHeight})`,
+ ]);
+ // The page scroller keeps the same strip clear.
+ const scroller = find('.main-content.mobile').find(r => r.media);
+ assert.equal(decl(scroller?.body ?? '', 'padding-top'), headerHeight);
+
+ // The language menu grows upward from the footer, and the drawer is a header shorter than the window: unbounded by
+ // that strip it rose over the header and the menu button (Arabic, whose footer is the tallest).
+ const menu = find('.sidebar.mobile .language-menu-list').find(r => r.media);
+ assert.deepEqual(valuesOf(menu?.body ?? '', 'max-height'), [
+ `calc(100vh - 13rem - ${headerHeight})`,
+ `calc(100dvh - 13rem - ${headerHeight})`,
+ ]);
+
+ const overlay = find('.sidebar-overlay').find(r => r.media);
+ assert.ok(
+ Number(decl(header.body, 'z-index')) > Number(decl(overlay?.body ?? '', 'z-index')),
+ 'the overlay dims the button',
+ );
+});
+
test('the language menu is bounded by the dynamic viewport too, since it hangs off the sidebar bottom', () => {
const menu = find('.language-menu-list').find(r => !r.media);
assert.deepEqual(valuesOf(menu?.body ?? '', 'max-height'), ['calc(100vh - 13rem)', 'calc(100dvh - 13rem)']);
diff --git a/dashboard/src/components/Layout.test.ts b/dashboard/src/components/Layout.test.ts
index 6649a457c..e60257a69 100644
--- a/dashboard/src/components/Layout.test.ts
+++ b/dashboard/src/components/Layout.test.ts
@@ -113,6 +113,69 @@ test('a collapsed sidebar shows its labels in the phone drawer and collapses aga
}
});
+// The phone drawer is opened and closed with the header menu button. The button said "Expand" in both states and did
+// not expose whether the drawer was open, and Escape (the one way a keyboard or switch user dismisses an overlay) did
+// nothing.
+test('the phone menu button names its state and Escape closes the drawer and returns focus to it', () => {
+ const width = window.innerWidth;
+ try {
+ window.innerWidth = 390;
+ const { container } = renderLayout();
+ const sidebar = container.querySelector('aside.sidebar')!;
+ const button = container.querySelector<HTMLButtonElement>('.mobile-menu-btn')!;
+ assert.equal(button.getAttribute('aria-expanded'), 'false');
+ assert.equal(button.getAttribute('aria-label'), 'Expand');
+
+ rtl.fireEvent.click(button);
+ assert.ok(sidebar.classList.contains('open'));
+ assert.equal(button.getAttribute('aria-expanded'), 'true');
+ assert.equal(button.getAttribute('aria-label'), 'Close');
+ assert.ok(rtl.screen.getByRole('button', { name: 'Close' }) === button);
+
+ rtl.fireEvent.click(button);
+ assert.ok(!sidebar.classList.contains('open'));
+ assert.equal(button.getAttribute('aria-expanded'), 'false');
+ assert.equal(button.getAttribute('aria-label'), 'Expand');
+
+ // Escape from inside the drawer: it closes, and focus lands on the button rather than on a link now off screen.
+ rtl.fireEvent.click(button);
+ rtl.screen.getByRole('link', { name: 'Sessions' }).focus();
+ rtl.fireEvent.keyDown(document, { key: 'Escape' });
+ assert.ok(!sidebar.classList.contains('open'), 'Escape left the drawer open');
+ assert.equal(button.getAttribute('aria-expanded'), 'false');
+ assert.ok(document.activeElement === button, `focus is on ${document.activeElement?.className}`);
+
+ // Closed, Escape is not listened for: it must not pull focus to the button.
+ rtl.screen.getByRole('link', { name: 'Sessions' }).focus();
+ rtl.fireEvent.keyDown(document, { key: 'Escape' });
+ assert.ok(document.activeElement !== button, 'Escape moved focus while the drawer was closed');
+ } finally {
+ window.innerWidth = width;
+ }
+});
+
+// The language menu lives in the drawer footer; Escape dismisses the innermost overlay first.
+test('Escape closes the open language menu before the phone drawer', () => {
+ const width = window.innerWidth;
+ try {
+ window.innerWidth = 390;
+ const { container } = renderLayout();
+ const sidebar = container.querySelector('aside.sidebar')!;
+ rtl.fireEvent.click(container.querySelector('.mobile-menu-btn')!);
+ rtl.fireEvent.click(container.querySelector('.language-menu .theme-toggle-btn')!);
+ assert.ok(container.querySelector('.language-menu-list'));
+
+ rtl.fireEvent.keyDown(document, { key: 'Escape' });
+ assert.equal(container.querySelector('.language-menu-list'), null, 'Escape left the language menu open');
+ assert.ok(sidebar.classList.contains('open'), 'the same Escape also closed the drawer');
+
+ rtl.fireEvent.keyDown(document, { key: 'Escape' });
+ assert.ok(!sidebar.classList.contains('open'), 'a second Escape left the drawer open');
+ } finally {
+ window.innerWidth = width;
+ }
+});
+
// The key management, infrastructure and plugin routes refuse a key restricted to selected sessions, whatever
// its role, and every refusal lands in the audit log as a failed attempt.
test('an admin key scoped to sessions is not offered the pages that refuse it', async () => {
diff --git a/dashboard/src/components/Layout.tsx b/dashboard/src/components/Layout.tsx
index 8c1b9b9ec..5c9bf1d3c 100644
--- a/dashboard/src/components/Layout.tsx
+++ b/dashboard/src/components/Layout.tsx
@@ -82,6 +82,7 @@ export function Layout({ onLogout, userRole }: LayoutProps) {
const [update, setUpdate] = useState<{ latest: string; url: string } | null>(null);
const [isLanguageMenuOpen, setIsLanguageMenuOpen] = useState(false);
const languageMenuRef = useRef<HTMLDivElement>(null);
+ const mobileMenuButtonRef = useRef<HTMLButtonElement>(null);
useEffect(() => {
const handleResize = () => {
@@ -137,6 +138,21 @@ export function Layout({ onLogout, userRole }: LayoutProps) {
};
}, [isMobileOpen]);
+ // Escape dismisses the innermost overlay: while the language menu is open it takes the key, then the drawer does.
+ useEffect(() => {
+ if (!isMobileOpen || isLanguageMenuOpen) return;
+
+ const closeOnEscape = (event: KeyboardEvent) => {
+ if (event.key !== 'Escape') return;
+ setIsMobileOpen(false);
+ // The focused link is about to slide off screen, so hand focus back to the control that opened the drawer.
+ mobileMenuButtonRef.current?.focus();
+ };
+
+ document.addEventListener('keydown', closeOnEscape);
+ return () => document.removeEventListener('keydown', closeOnEscape);
+ }, [isMobileOpen, isLanguageMenuOpen]);
+
useEffect(() => {
if (!isLanguageMenuOpen) return;
@@ -172,7 +188,13 @@ export function Layout({ onLogout, userRole }: LayoutProps) {
<div className="layout">
{isMobile && (
<header className="mobile-header">
- <button className="mobile-menu-btn" onClick={toggleMobile} aria-label={t('common.expand')}>
+ <button
+ ref={mobileMenuButtonRef}
+ className="mobile-menu-btn"
+ onClick={toggleMobile}
+ aria-label={isMobileOpen ? t('common.close') : t('common.expand')}
+ aria-expanded={isMobileOpen}
+ >
{isMobileOpen ? <X size={24} /> : <Menu size={24} />}
</button>
<div className="mobile-brand">