Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): restore the chat page headings and panel focus

Yudhi Armyndharis841283e5e308
diff --git a/dashboard/src/pages/Chats.css b/dashboard/src/pages/Chats.css
index 086b51913..d861566dd 100644
--- a/dashboard/src/pages/Chats.css
+++ b/dashboard/src/pages/Chats.css
@@ -89,6 +89,19 @@
}
}
+/* Read by screen readers only: the page and the open room keep their headings without showing them. */
+.chats-page .visually-hidden {
+ position: absolute;
+ width: 1px;
+ height: 1px;
+ margin: -1px;
+ padding: 0;
+ overflow: hidden;
+ clip-path: inset(50%);
+ white-space: nowrap;
+ border: 0;
+}
+
.chats-page .chats-layout {
display: flex;
flex: 1;
diff --git a/dashboard/src/pages/Chats.features.test.ts b/dashboard/src/pages/Chats.features.test.ts
index 6cf9db18d..8b3b77047 100644
--- a/dashboard/src/pages/Chats.features.test.ts
+++ b/dashboard/src/pages/Chats.features.test.ts
@@ -475,6 +475,39 @@ test('the contact panel opens from the room header and Escape closes it before t
assert.ok(container.querySelector('.room-header'), 'Escape closed the room along with the panel');
});
+test('the page and the open room keep a heading, and closing the panel returns focus to its toggle', async () => {
+ const { screen, fireEvent, waitFor, within } = rtl;
+ const { container } = renderPage();
+ assert.ok(screen.getByRole('heading', { level: 1, name: 'Chats' }), 'the page has no h1');
+ fireEvent.click(await screen.findByText('Alice'));
+ await waitFor(() => assert.ok(screen.getByRole('heading', { level: 2, name: 'Alice' }), 'the room has no heading'));
+
+ const focusedName = () => document.activeElement?.getAttribute('aria-label');
+ fireEvent.click(screen.getByRole('button', { name: 'Contact info' }));
+ const panel = await waitFor(() => container.querySelector('.contact-info-panel') as HTMLElement);
+ fireEvent.click(within(panel).getByRole('button', { name: 'Close' }));
+ assert.equal(container.querySelector('.contact-info-panel'), null, 'the close button left the panel open');
+ assert.equal(focusedName(), 'Contact info', 'closing the panel dropped focus');
+
+ fireEvent.click(screen.getByRole('button', { name: 'Contact info' }));
+ await waitFor(() => assert.ok(container.querySelector('.contact-info-panel')));
+ (container.querySelector('.contact-info-panel button') as HTMLElement).focus();
+ fireEvent.keyDown(document, { key: 'Escape' });
+ assert.equal(container.querySelector('.contact-info-panel'), null, 'Escape left the panel open');
+ assert.equal(focusedName(), 'Contact info', 'Escape dropped focus');
+});
+
+test("a group's panel is its group info, not contact info", async () => {
+ const { screen, fireEvent, waitFor } = rtl;
+ listGroup = true;
+ const { container } = renderPage();
+ fireEvent.click(await screen.findByText('Team'));
+ await waitFor(() => assert.ok(container.querySelector('.room-header'), 'the room did not open'));
+ assert.ok(!screen.queryByRole('button', { name: 'Contact info' }), 'a group offers contact info');
+ fireEvent.click(screen.getByRole('button', { name: 'Group info' }));
+ assert.ok(await screen.findByRole('complementary', { name: 'Group info' }), 'the group panel is not named for it');
+});
+
test('the contact panel isolates the chat id left to right, so an RTL page keeps "@c.us" at its end', async () => {
const { screen, fireEvent, waitFor, within } = rtl;
const { container } = renderPage();
diff --git a/dashboard/src/pages/Chats.tsx b/dashboard/src/pages/Chats.tsx
index 6bb2adabd..21c408399 100644
--- a/dashboard/src/pages/Chats.tsx
+++ b/dashboard/src/pages/Chats.tsx
@@ -233,6 +233,13 @@ export function Chats() {
const openRoomKey = activeChat ? readKey(selectedSessionId, activeChat.id) : '';
if (contactInfoFor !== '' && contactInfoFor !== openRoomKey) setContactInfoFor('');
const showContactInfo = contactInfoFor !== '' && contactInfoFor === openRoomKey;
+ const contactInfoLabel = activeChat?.isGroup ? t('chats.group.info') : t('chats.contactInfo');
+ // Closing the panel unmounts its close button, so focus goes back to the button that toggles it.
+ const contactToggleRef = useRef<HTMLButtonElement | null>(null);
+ const closeContactInfo = () => {
+ setContactInfoFor('');
+ contactToggleRef.current?.focus();
+ };
// Chats/Channels/Status tab selection. Switching tabs closes whatever conversation is open so a
// press on another tab doesn't leave a Chats-tab room rendered underneath a Channels/Status list.
@@ -1767,8 +1774,10 @@ export function Chats() {
if (document.querySelector('[role="dialog"], [role="menu"]')) return;
if (activeStatusContactId !== null) setActiveStatusContactId(null);
else if (activeChannel) setActiveChannel(null);
- else if (activeChat && showContactInfo) setContactInfoFor('');
- else if (activeChat) setActiveChat(null);
+ else if (activeChat && showContactInfo) {
+ setContactInfoFor('');
+ contactToggleRef.current?.focus();
+ } else if (activeChat) setActiveChat(null);
else if (showNewChat) setShowNewChat(false);
else return;
event.preventDefault();
@@ -1796,6 +1805,8 @@ export function Chats() {
return (
<div className="chats-page">
+ {/* The page header gave way to the full-height layout; its title stays for screen readers. */}
+ <h1 className="visually-hidden">{t('nav.chats')}</h1>
{/* Real-time connection permanently dropped — let the user re-establish it instead of
silently showing stale chats. */}
{connectionFailed && (
@@ -1916,6 +1927,7 @@ export function Chats() {
<div className="chats-room">
{activeChat ? (
<div className="room-container">
+ <h2 className="visually-hidden">{activeChatTitle}</h2>
{/* Room header */}
<header className="room-header">
<button className="room-back" onClick={() => setActiveChat(null)} aria-label={t('common.back')}>
@@ -1926,7 +1938,7 @@ export function Chats() {
type="button"
className="room-contact"
onClick={() => setContactInfoFor(showContactInfo ? '' : openRoomKey)}
- title={t('chats.contactInfo')}
+ title={contactInfoLabel}
aria-expanded={showContactInfo}
>
<ChatAvatar
@@ -1998,11 +2010,12 @@ export function Chats() {
)}
</div>
<button
+ ref={contactToggleRef}
type="button"
className={`icon-btn ${showContactInfo ? 'active' : ''}`}
onClick={() => setContactInfoFor(showContactInfo ? '' : openRoomKey)}
- title={t('chats.contactInfo')}
- aria-label={t('chats.contactInfo')}
+ title={contactInfoLabel}
+ aria-label={contactInfoLabel}
aria-pressed={showContactInfo}
>
<PanelRight size={22} />
@@ -2154,18 +2167,18 @@ export function Chats() {
{/* Contact panel beside the room, toggled from its header. */}
{activeChat && showContactInfo && (
- <aside className="contact-info-panel" aria-label={t('chats.contactInfo')}>
+ <aside className="contact-info-panel" aria-label={contactInfoLabel}>
<header className="contact-info-header">
<button
type="button"
className="icon-btn"
- onClick={() => setContactInfoFor('')}
+ onClick={closeContactInfo}
aria-label={t('common.close')}
title={t('common.close')}
>
<X size={20} />
</button>
- <span>{t('chats.contactInfo')}</span>
+ <span>{contactInfoLabel}</span>
</header>
<div className="contact-info-body">
<ChatAvatar