From cc587f6c5be57828df1c42749385d34da91e6e38 Mon Sep 17 00:00:00 2001
From: Linus Rath <139418639+rathlinus@users.noreply.github.com>
Date: Wed, 4 Nov 2026 16:38:00 +0100
Subject: [PATCH 1/8] refactor: share the folder drawer's focus handling and
dimmed backdrop with other sidebars
---
app/globals.css | 5 +-
.../layout/__tests__/edge-drawer.test.tsx | 53 ++++++++++++++
components/layout/edge-drawer.tsx | 73 +++++++++++++++++++
components/mail/mail-app.tsx | 53 +++++---------
hooks/use-edge-drawer.ts | 72 ++++++++++++++++++
5 files changed, 219 insertions(+), 37 deletions(-)
create mode 100644 components/layout/__tests__/edge-drawer.test.tsx
create mode 100644 components/layout/edge-drawer.tsx
create mode 100644 hooks/use-edge-drawer.ts
diff --git a/app/globals.css b/app/globals.css
index 4e41210eb..f9eb2c995 100644
--- a/app/globals.css
+++ b/app/globals.css
@@ -617,8 +617,9 @@ optgroup {
--titlebar-right-inset: calc(100vw - env(titlebar-area-x, 0px) - env(titlebar-area-width, 100vw));
--titlebar-left-inset: env(titlebar-area-x, 0px);
--titlebar-row-height: env(titlebar-area-height, 0px);
- /* Where a drawer from the window's edge starts (the folder drawer): under
- the top bar, and under the window's controls when they are over the page. */
+ /* Where a drawer from the window's edge starts (Mail's folders, the
+ Calendar, Contacts and Files sidebars): under the top bar, and under the
+ window's controls when they are over the page. */
--drawer-top: max(var(--app-top-inset), var(--titlebar-row-height));
}
diff --git a/components/layout/__tests__/edge-drawer.test.tsx b/components/layout/__tests__/edge-drawer.test.tsx
new file mode 100644
index 000000000..04ac3b893
--- /dev/null
+++ b/components/layout/__tests__/edge-drawer.test.tsx
@@ -0,0 +1,53 @@
+import { useState } from 'react';
+import { act, fireEvent, render, screen } from '@testing-library/react';
+import { describe, expect, it } from 'vitest';
+import { EdgeDrawer } from '../edge-drawer';
+
+// The drawer Calendar, Contacts and Files open below the full desktop, with
+// the keyboard side Mail's phone drawer uses too (useEdgeDrawer).
+
+function Harness({ contained = false, onPickFocus }: { contained?: boolean; onPickFocus?: () => void }) {
+ const [open, setOpen] = useState(false);
+ return (
+ <>
+
+
+ setOpen(false)} contained={contained} data-testid="drawer">
+
+
+
+
+ >
+ );
+}
+
+describe('EdgeDrawer', () => {
+ it('opens on the current item and gives the focus back to the opener after a pick', () => {
+ render();
+ const menu = screen.getByText('menu');
+ menu.focus();
+ fireEvent.click(menu);
+ expect(document.activeElement).toBe(screen.getByText('current'));
+ fireEvent.click(screen.getByText('pick'));
+ expect(screen.getByTestId('drawer')).toHaveAttribute('inert');
+ expect(document.activeElement).toBe(menu);
+ });
+
+ it('leaves the focus where a pick moved it, outside the drawer', () => {
+ render( screen.getByLabelText('elsewhere').focus()} />);
+ const menu = screen.getByText('menu');
+ menu.focus();
+ fireEvent.click(menu);
+ act(() => fireEvent.click(screen.getByText('pick')));
+ expect(document.activeElement).toBe(screen.getByLabelText('elsewhere'));
+ });
+
+ it('stays inside a Pro pane: at the pane\'s edge, with only the pane dimmed', () => {
+ render();
+ fireEvent.click(screen.getByText('menu'));
+ const classes = screen.getByTestId('drawer').className.split(/\s+/);
+ expect(classes).toEqual(expect.arrayContaining(['absolute', 'inset-y-0', 'start-0']));
+ expect(classes).not.toContain('fixed');
+ expect(screen.getByTestId('drawer-scrim').className.split(/\s+/)).toContain('absolute');
+ });
+});
diff --git a/components/layout/edge-drawer.tsx b/components/layout/edge-drawer.tsx
new file mode 100644
index 000000000..616a6e30f
--- /dev/null
+++ b/components/layout/edge-drawer.tsx
@@ -0,0 +1,73 @@
+"use client";
+
+import type { HTMLAttributes, ReactNode } from "react";
+import { cn } from "@/lib/utils";
+import { useEdgeDrawer } from "@/hooks/use-edge-drawer";
+
+interface DrawerScrimProps {
+ onClose: () => void;
+ /** In a Pro pane: dims the pane only, not the other one beside it. */
+ contained?: boolean;
+ className?: string;
+ "data-testid"?: string;
+}
+
+/**
+ * The dimmed page behind a drawer. A click on it closes the drawer; the
+ * click, not the press, so it can't go through to what is under it.
+ */
+export function DrawerScrim({ onClose, contained, className, "data-testid": testId = "drawer-scrim" }: DrawerScrimProps) {
+ return (
+
onClose()}
+ />
+ );
+}
+
+interface EdgeDrawerProps extends Omit, "children"> {
+ open: boolean;
+ onClose: () => void;
+ /**
+ * In a Pro pane or Mountain View's card: at the start edge of the nearest
+ * positioned box instead of the window's.
+ */
+ contained?: boolean;
+ /** Where the focus goes back to when the opener is gone by then. */
+ returnFocus?: () => HTMLElement | null | undefined;
+ children: ReactNode;
+}
+
+/**
+ * A sidebar opened over the page below the full desktop, as Mail's folders
+ * do: from the window's start edge (the right in RTL), over the app rail,
+ * from under the top bar and the window's controls (--drawer-top) to the
+ * bottom, with the page dimmed behind it. Keyboard and focus: useEdgeDrawer.
+ * Closed, it is off-screen and out of reach: no clicks, no Tab stops.
+ */
+export function EdgeDrawer({ open, onClose, contained, returnFocus, className, children, ...rest }: EdgeDrawerProps) {
+ const ref = useEdgeDrawer({ open, onClose, returnFocus });
+ return (
+ <>
+ {open && }
+
+ {children}
+
+ >
+ );
+}
diff --git a/components/mail/mail-app.tsx b/components/mail/mail-app.tsx
index 8ac8ecbe9..825c20a29 100644
--- a/components/mail/mail-app.tsx
+++ b/components/mail/mail-app.tsx
@@ -79,7 +79,8 @@ import { useContactStore } from "@/stores/contact-store";
import { useIdentityStore } from "@/stores/identity-store";
import { useUIStore, sidebarFolded, listPaneCssSize, SIDEBAR_MIN, SIDEBAR_MAX, EMAIL_LIST_MIN, EMAIL_LIST_MAX, EMAIL_LIST_HEIGHT_MIN, EMAIL_LIST_HEIGHT_MAX, READING_PANE_MIN_WIDTH, READING_PANE_MIN_HEIGHT, COMPOSER_PANE_MIN_HEIGHT } from "@/stores/ui-store";
import { atLeast, PHONE_BELOW, useDeviceDetection } from "@/hooks/use-media-query";
-import { useFocusTrap } from "@/hooks/use-focus-trap";
+import { useEdgeDrawer } from "@/hooks/use-edge-drawer";
+import { DrawerScrim } from "@/components/layout/edge-drawer";
import { usePaneSize } from "@/hooks/use-pane-size";
import { useIsFocusedProTab, usePaneId } from "@/hooks/use-pane-context";
import { useKeyboardShortcuts, type GoToMailboxTarget } from "@/hooks/use-keyboard-shortcuts";
@@ -2594,29 +2595,18 @@ export function MailApp({ linkSegments: routeSegments }: MailAppProps = {}) {
// Pro can mount two mail panes at once, so the sidebar id must be per-instance.
const sidebarId = useId();
const listHeadingId = useId();
- // The phone drawer keeps Tab inside until it closes, and Escape closes it.
+ // The phone drawer keeps Tab inside until it closes, Escape closes it, and
+ // the focus goes back to the toggle however it closes (Escape, X, a pick,
+ // the scrim), unless it has moved on to something outside the drawer. The
+ // toggle lives in whichever MobileHeader the current view renders, so it is
+ // looked up inside this app instance when the one that opened it is gone.
const phoneDrawerOpen = isMobile && sidebarOpen;
- const sidebarContainerRef = useFocusTrap({
- isActive: phoneDrawerOpen,
- onEscape: () => setSidebarOpen(false),
- restoreFocus: false,
+ const closeSidebarDrawer = useCallback(() => setSidebarOpen(false), [setSidebarOpen]);
+ const sidebarContainerRef = useEdgeDrawer({
+ open: phoneDrawerOpen,
+ onClose: closeSidebarDrawer,
+ returnFocus: () => appRootRef.current?.querySelector('[data-sidebar-toggle]'),
});
- const sidebarWasOpen = useRef(false);
- useEffect(() => {
- if (phoneDrawerOpen) {
- sidebarWasOpen.current = true;
- return;
- }
- if (!sidebarWasOpen.current) return;
- sidebarWasOpen.current = false;
- // Back to the toggle however it closed (Escape, X, a pick, the scrim),
- // unless the focus has moved on to something outside the drawer. The
- // toggle lives in whichever MobileHeader the current view renders, so
- // look it up inside this app instance rather than threading a ref through.
- const active = document.activeElement;
- if (active && active !== document.body && !sidebarContainerRef.current?.contains(active)) return;
- appRootRef.current?.querySelector('[data-sidebar-toggle]')?.focus();
- }, [phoneDrawerOpen, sidebarContainerRef]);
// The folded column's tree open over the page as a drawer (Sidebar's
// onDrawerChange): the function that closes it, for the scrim.
const [closeFolderDrawer, setCloseFolderDrawer] = useState<(() => void) | null>(null);
@@ -5850,20 +5840,13 @@ export function MailApp({ linkSegments: routeSegments }: MailAppProps = {}) {
scope to the pane via `absolute` so the backdrop stays inside
the pane instead of covering the whole window. */}
{((isMobile && sidebarOpen) || closeFolderDrawer) && !inlineApp && (
-
{
- if (closeFolderDrawer) closeFolderDrawer();
- else setSidebarOpen(false);
- }}
+ contained={isEmbedded}
+ // The folded column's drawer opens on a desktop, so only the
+ // phone's scrim goes with the phone layout.
+ className={!isEmbedded && !closeFolderDrawer ? "desk:hidden" : undefined}
+ onClose={closeFolderDrawer ?? closeSidebarDrawer}
/>
)}
diff --git a/hooks/use-edge-drawer.ts b/hooks/use-edge-drawer.ts
new file mode 100644
index 000000000..f0da905a7
--- /dev/null
+++ b/hooks/use-edge-drawer.ts
@@ -0,0 +1,72 @@
+import { useEffect, useLayoutEffect, useRef } from 'react';
+import { useFocusTrap } from '@/hooks/use-focus-trap';
+
+interface UseEdgeDrawerOptions {
+ /** Whether the drawer is open over the page. */
+ open: boolean;
+ /** Closes it: Escape, and whatever else the caller wires (scrim, X, a pick). */
+ onClose: () => void;
+ /**
+ * Where the focus goes back to when the button that opened the drawer is
+ * gone by then (a header that rendered again).
+ */
+ returnFocus?: () => HTMLElement | null | undefined;
+}
+
+/**
+ * The keyboard side of a sidebar opened over the page as a drawer (Mail's
+ * folders on a phone, Calendar, Contacts and Files below the full desktop):
+ * the focus goes to the current item in it, else the first, Tab stays inside
+ * until it closes, Escape closes it, and however it closes (Escape, the scrim,
+ * a close button, a pick) the focus goes back to the button that opened it,
+ * unless the pick moved it somewhere else on purpose.
+ *
+ * Returns the ref for the drawer's element.
+ */
+export function useEdgeDrawer({ open, onClose, returnFocus }: UseEdgeDrawerOptions) {
+ const ref = useFocusTrap({
+ isActive: open,
+ onEscape: onClose,
+ restoreFocus: false,
+ initialFocus: () => ref.current?.querySelector(
+ '[aria-current]:not(:disabled):not([tabindex="-1"])'
+ ),
+ });
+
+ // The opener, read before the trap moves the focus into the drawer.
+ const openerRef = useRef(null);
+ const returnFocusRef = useRef(returnFocus);
+ useLayoutEffect(() => {
+ returnFocusRef.current = returnFocus;
+ if (!open) return;
+ const active = document.activeElement;
+ if (active instanceof HTMLElement && active !== document.body && !ref.current?.contains(active)) {
+ openerRef.current = active;
+ }
+ });
+
+ const wasOpen = useRef(false);
+ useEffect(() => {
+ if (open) {
+ wasOpen.current = true;
+ // The current item can sit in a folded group: then the first one.
+ const root = ref.current;
+ if (root && !root.contains(document.activeElement)) {
+ root.querySelector(
+ 'button:not(:disabled), [href], input:not(:disabled), [tabindex]:not([tabindex="-1"])'
+ )?.focus();
+ }
+ return;
+ }
+ if (!wasOpen.current) return;
+ wasOpen.current = false;
+ const active = document.activeElement;
+ // A pick that moved the focus on (a dialog, a form) keeps it there.
+ if (active && active !== document.body && !ref.current?.contains(active)) return;
+ const opener = openerRef.current;
+ openerRef.current = null;
+ (opener?.isConnected ? opener : returnFocusRef.current?.())?.focus();
+ }, [open, ref]);
+
+ return ref;
+}
From b1fed8144b83afe1ce3efb8415f6e0eda8927924 Mon Sep 17 00:00:00 2001
From: Linus Rath <139418639+rathlinus@users.noreply.github.com>
Date: Wed, 4 Nov 2026 16:38:31 +0100
Subject: [PATCH 2/8] fix: open the Calendar, Contacts and Files sidebars in a
narrow window as a drawer from the window's edge, like the folder list
---
.../calendar/__tests__/calendar-app.test.tsx | 53 ++++
components/calendar/calendar-app.tsx | 246 +++++++++---------
.../contacts/__tests__/contacts-app.test.tsx | 42 +++
components/contacts/contacts-app.tsx | 194 +++++++-------
components/contacts/contacts-sidebar.tsx | 3 +
.../file-browser-shared-folders.test.tsx | 47 ++++
components/files/file-browser.tsx | 32 +--
7 files changed, 384 insertions(+), 233 deletions(-)
diff --git a/components/calendar/__tests__/calendar-app.test.tsx b/components/calendar/__tests__/calendar-app.test.tsx
index f02537e85..2b48c34bd 100644
--- a/components/calendar/__tests__/calendar-app.test.tsx
+++ b/components/calendar/__tests__/calendar-app.test.tsx
@@ -866,3 +866,56 @@ describe('CalendarApp company calendars on a phone', () => {
}
});
});
+
+// Below the full desktop the sidebar is the same drawer as Mail's folders
+// (usability test 2026-11-04): from the window's edge, the page dimmed,
+// Escape closes it, and the focus goes in and back to the menu button.
+describe('CalendarApp sidebar drawer', () => {
+ beforeEach(() => {
+ media.desktop = false;
+ });
+
+ const drawer = () => screen.getByTestId('calendar-sidebar-drawer');
+ const menu = () => screen.getByRole('button', { name: 'nav_open_menu' });
+
+ it("opens from the window's edge, over the app rail and under the top bar", () => {
+ renderApp();
+ const classes = drawer().className.split(/\s+/);
+ expect(classes).toEqual(expect.arrayContaining(['fixed', 'start-0', 'top-[var(--drawer-top)]', 'bottom-0']));
+ expect(classes).not.toContain('absolute');
+ });
+
+ it("is out of reach while closed, so Tab doesn't walk into the hidden calendars", () => {
+ renderApp();
+ expect(drawer()).toHaveAttribute('inert');
+ fireEvent.click(menu());
+ expect(drawer()).not.toHaveAttribute('inert');
+ });
+
+ it('takes the focus in, keeps Tab there and gives it back to the menu button on Escape', () => {
+ renderApp();
+ menu().focus();
+ fireEvent.click(menu());
+ expect(drawer().contains(document.activeElement)).toBe(true);
+ const stops = Array.from(drawer().querySelectorAll('button:not(:disabled)'));
+ stops.at(-1)!.focus();
+ fireEvent.keyDown(stops.at(-1)!, { key: 'Tab' });
+ expect(document.activeElement).toBe(stops[0]);
+
+ fireEvent.keyDown(document.activeElement!, { key: 'Escape' });
+ expect(drawer()).toHaveAttribute('inert');
+ expect(document.activeElement).toBe(menu());
+ });
+
+ it('closes on a click on the dimmed window and gives the focus back to the menu button', () => {
+ renderApp();
+ menu().focus();
+ fireEvent.click(menu());
+ const scrim = screen.getByTestId('drawer-scrim');
+ expect(scrim.className.split(/\s+/)).toEqual(expect.arrayContaining(['fixed', 'inset-0']));
+ (document.activeElement as HTMLElement).blur();
+ fireEvent.click(scrim);
+ expect(drawer()).toHaveAttribute('inert');
+ expect(document.activeElement).toBe(menu());
+ });
+});
diff --git a/components/calendar/calendar-app.tsx b/components/calendar/calendar-app.tsx
index 9bda4c125..81ced90b4 100644
--- a/components/calendar/calendar-app.tsx
+++ b/components/calendar/calendar-app.tsx
@@ -60,6 +60,7 @@ import { useIsFocusedProTab, useIsPaneScoped } from "@/hooks/use-pane-context";
import { useProMultiAccountCalendars } from "@/hooks/use-pro-multi-account-calendars";
import { useEventUserEmails } from "@/hooks/use-event-user-emails";
import { ResizeHandle } from "@/components/layout/resize-handle";
+import { EdgeDrawer } from "@/components/layout/edge-drawer";
import { descriptionWithNote } from "@/lib/calendar-description";
import { filterTasksByCalendars } from "@/lib/calendar-tasks";
import { baseEventStoreId, isServerRecurrenceInstance } from "@/lib/recurrence-instances";
@@ -183,6 +184,7 @@ export function CalendarApp({ linkSegments: routeSegments }: CalendarAppProps =
// collapses into a burger-toggled overlay instead of taking inline space.
const isNarrow = !isFullDesktop;
const [narrowSidebarOpen, setNarrowSidebarOpen] = useState(false);
+ const closeNarrowSidebar = useCallback(() => setNarrowSidebarOpen(false), []);
useEffect(() => { if (!isNarrow) setNarrowSidebarOpen(false); }, [isNarrow]);
const { showAppsModal, inlineApp, loadedApps, handleManageApps, handleInlineApp, closeInlineApp, closeAppsModal } = useSidebarApps();
const { client, isAuthenticated, logout, checkAuth, switchAccount, activeAccountId, isLoading: authLoading } = useAuthStore();
@@ -2218,6 +2220,97 @@ export function CalendarApp({ linkSegments: routeSegments }: CalendarAppProps =
/>
);
+ // The sidebar's content: beside the views on the full desktop, a drawer below it.
+ const calendarSidebar = (
+ <>
+ { setNarrowSidebarOpen(false); openCreateForView(); }}
+ createLabel={createLabel}
+ tourTarget={!isNarrow}
+ />
+
+
+
+
+ {
+ if (calendarId === BIRTHDAY_CALENDAR_ID) {
+ updateSetting('birthdayCalendarColor', color);
+ return;
+ }
+ // Shared calendars: recolor locally only (the viewer usually
+ // can't write the owner's calendar, and it'd recolor it for
+ // everyone). Personal calendars write through to the server.
+ const cal = allCalendars.find((c) => c.id === calendarId);
+ if (cal?.isShared) {
+ setSharedCalendarColor(sharedCalendarColorKey(cal), color);
+ return;
+ }
+ updateCalendar(client, calendarId, { color });
+ } : undefined}
+ onResetColor={(cal) => {
+ // Drop the local override. A calendar with a server color goes
+ // back to it; one without gets a fresh unused color from the
+ // auto-assign effect (so it never reverts to a collision).
+ removeSharedCalendarColor(sharedCalendarColorKey(cal));
+ }}
+ onShareCalendar={client ? (cal) => setSharingCalendarId(cal.id) : undefined}
+ onCreateEvent={(cal: Calendar) => {
+ setDefaultCalendarIdForCreate(cal.id);
+ openCreateModal();
+ }}
+ onClearCalendar={client ? async (cal: Calendar) => {
+ const ok = await confirmAction({
+ title: tMgmt("clear_events"),
+ message: tMgmt("confirm_clear", { name: shownName.calendar(cal) }),
+ variant: "destructive",
+ confirmText: tMgmt("clear_events"),
+ });
+ if (!ok) return;
+ try {
+ const count = await clearCalendarEvents(client, cal.id);
+ toast.success(tMgmt("events_cleared", { count }));
+ } catch (err) {
+ // The store rethrows the server's reason (#434).
+ toast.error(err instanceof Error && err.message ? err.message : tMgmt("error_clear"));
+ }
+ } : undefined}
+ onDeleteCalendar={client ? async (cal: Calendar) => {
+ const ok = await confirmAction({
+ title: tMgmt("delete"),
+ message: tMgmt("confirm_delete", { name: shownName.calendar(cal) }),
+ variant: "destructive",
+ confirmText: tMgmt("delete"),
+ });
+ if (!ok) return;
+ try {
+ await removeCalendar(client, cal.id);
+ toast.success(tMgmt("calendar_deleted"));
+ } catch {
+ toast.error(tMgmt("error_delete"));
+ }
+ } : undefined}
+ onCreateCalendar={client ? () => setShowCreateCalendar(true) : undefined}
+ onSubscribe={canSubscribe ? () => setShowSubscriptionModal(true) : undefined}
+ onEditSubscription={(subId) => setEditingSubscription(subId)}
+ client={client}
+ multiAccountMode={multiAccountEnabled && accountClients.length > 1}
+ />
+
+ >
+ );
+
return (
{!isEmbedded && {tShell("skip_to_content")}}
@@ -2253,138 +2346,49 @@ export function CalendarApp({ linkSegments: routeSegments }: CalendarAppProps =
)}
- {/* Narrow-pane backdrop: dim and close overlay sidebar */}
- {isNarrow && narrowSidebarOpen && !inlineApp && (
-
- {/* Sidebar - in-flow when desktop pane, overlay when narrow */}
- {(isNarrow || !sidebarCollapsed) && (
+ {/* The sidebar: in flow on the full desktop; below it a drawer from
+ the window's edge, over the app rail, as Mail's folders. */}
+ {isNarrow && (
+
+ {calendarSidebar}
+
+ )}
+ {!isNarrow && !sidebarCollapsed && (
<>