Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

feat(dashboard): close the open chat, channel or status with Escape

Cares T.386548f0e4a2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a5c7f9ca1..78d44ab45 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Added
+
+- On the dashboard Chats page, Escape closes the open chat, channel or status viewer and returns to the list. It leaves the key alone while a dialog, a menu or the media viewer is open, since those handle Escape themselves.
+
### Changed
- The PostgreSQL data connection is pinned to UTC: parameters bind as UTC, naive timestamps read back as UTC, every pooled connection sets its session `TimeZone`, and boot fails when the effective zone is not UTC year round.
diff --git a/dashboard/src/pages/Chats.tsx b/dashboard/src/pages/Chats.tsx
index 1b7951fa7..b42f9ae47 100644
--- a/dashboard/src/pages/Chats.tsx
+++ b/dashboard/src/pages/Chats.tsx
@@ -790,6 +790,21 @@ export function Chats() {
if (el) el.scrollTop = el.scrollHeight;
}, [activeStatusGroup?.contact.id, activeStatusGroup?.items]);
+ useEffect(() => {
+ const closeTopmostViewOnEscape = (event: KeyboardEvent) => {
+ if (event.key !== 'Escape' || event.defaultPrevented || event.isComposing) return;
+ if (document.querySelector('[role="dialog"], [role="menu"]')) return;
+ if (lightboxIndex !== null) setLightboxIndex(null);
+ else if (activeStatusContactId !== null) setActiveStatusContactId(null);
+ else if (activeChannel) setActiveChannel(null);
+ else if (activeChat) setActiveChat(null);
+ else return;
+ event.preventDefault();
+ };
+ document.addEventListener('keydown', closeTopmostViewOnEscape);
+ return () => document.removeEventListener('keydown', closeTopmostViewOnEscape);
+ }, [lightboxIndex, activeStatusContactId, activeChannel, activeChat]);
+
// Image media items for the lightbox, in render order. `getMediaSrc` reconstructs a usable src
// from either a base64 payload or a URL — the ChatMessageView shape stores both in `data`.
const imageMedia = useMemo<LightboxItem[]>(