Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

📱 fix: Keep the Mobile Drawer Open When a Dialog Opened From It Takes Escape (#17502)

Marco Beretta474a60070708
diff --git a/client/src/components/UnifiedSidebar/UnifiedSidebar.tsx b/client/src/components/UnifiedSidebar/UnifiedSidebar.tsx
index 36c88534dd..de1a9a58c9 100644
--- a/client/src/components/UnifiedSidebar/UnifiedSidebar.tsx
+++ b/client/src/components/UnifiedSidebar/UnifiedSidebar.tsx
@@ -194,6 +194,15 @@ function UnifiedSidebar({
if (e.key !== 'Escape') {
return;
}
+ /**
+ * A layer above the drawer already took this Escape: a dialog opened from
+ * the drawer dismisses itself and marks the event handled. Collapsing the
+ * drawer too would close two levels for one keystroke and drop the focus
+ * the dialog hands back to its trigger.
+ */
+ if (e.defaultPrevented) {
+ return;
+ }
/**
* Menus opened from the drawer portal out of it, so their Escape still
* reaches this listener. Dismissing the whole drawer would skip the level
diff --git a/e2e/specs/mock/scenarios/assistant-delete-dialog.spec.ts b/e2e/specs/mock/scenarios/assistant-delete-dialog.spec.ts
index 26e4001515..ba8f82175a 100644
--- a/e2e/specs/mock/scenarios/assistant-delete-dialog.spec.ts
+++ b/e2e/specs/mock/scenarios/assistant-delete-dialog.spec.ts
@@ -119,10 +119,13 @@ test.describe('assistant delete confirmation', () => {
dialog = await expectConfirmDialog(page);
await page.keyboard.press('Escape');
await expect(dialog).toBeHidden();
- /** The mobile drawer also collapses on that Escape, for every dialog opened from it
- * (berry-13/LibreChat#428), which takes the trigger with it. */
- if (!isMobile) {
- await expect(trigger).toBeFocused();
+ /** The dialog takes the Escape, so on mobile the drawer it was opened from stays open
+ * and the trigger is there to take focus back (berry-13/LibreChat#428). */
+ await expect(trigger).toBeFocused();
+ if (isMobile) {
+ await expect(
+ page.getByRole('button', { name: 'Close sidebar' }).filter({ visible: true }).first(),
+ ).toBeVisible();
}
expect(await assistantExists(page, assistant.id)).toBe(true);
diff --git a/e2e/specs/mock/scenarios/drawer-escape.spec.ts b/e2e/specs/mock/scenarios/drawer-escape.spec.ts
new file mode 100644
index 0000000000..1dd9efd1d1
--- /dev/null
+++ b/e2e/specs/mock/scenarios/drawer-escape.spec.ts
@@ -0,0 +1,34 @@
+import { expect, test } from '@playwright/test';
+import type { Page } from '@playwright/test';
+import { NEW_CHAT_PATH } from '../helpers';
+import { openSidebar } from './sidebar';
+
+/**
+ * On small screens the sidebar is a drawer that Escape collapses. It only does so when
+ * nothing above it took the Escape first (`assistant-delete-dialog-dismiss` covers a dialog
+ * opened from the drawer keeping it open).
+ */
+
+async function drawerOpen(page: Page): Promise<boolean> {
+ const closers = page.getByRole('button', { name: 'Close sidebar' });
+ const count = await closers.count();
+ for (let index = 0; index < count; index++) {
+ if (await closers.nth(index).isVisible()) {
+ return true;
+ }
+ }
+ return false;
+}
+
+test('Escape with nothing open above it collapses the mobile drawer @scenario:drawer-escape-collapses', async ({
+ page,
+ isMobile,
+}) => {
+ test.skip(!isMobile, 'The drawer exists on small screens only');
+ await page.goto(NEW_CHAT_PATH, { timeout: 15000 });
+ await openSidebar(page);
+ expect(await drawerOpen(page)).toBe(true);
+
+ await page.keyboard.press('Escape');
+ await expect.poll(() => drawerOpen(page)).toBe(false);
+});