diff --git a/app/globals.css b/app/globals.css index 7a0579c93..0c707eca0 100644 --- a/app/globals.css +++ b/app/globals.css @@ -313,6 +313,18 @@ optgroup { background-color: var(--color-muted-foreground); } +/* The folded folder column (components/layout/sidebar.tsx) leaves its 48px + to the icons: a 4px scrollbar, in a gutter kept on both sides. */ +:root:not([data-native-scrollbars="on"]) [data-folder-rail]::-webkit-scrollbar { + width: 4px; +} + +@supports not selector(::-webkit-scrollbar) { + :root:not([data-native-scrollbars="on"]) [data-folder-rail] { + scrollbar-width: thin; + } +} + /* Enhanced Email Content Styling */ .email-content-wrapper { @@ -617,8 +629,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)); } @@ -627,6 +640,17 @@ html[data-window-controls] [data-window-row-right] { padding-right: calc(var(--titlebar-right-inset) + 0.5rem) !important; } +/* + * The composer's header runs over its plugin panels. The head above the panel at the + * window's right takes that room inside itself, so it stays as wide as the panel and + * its Hide button stays at the panel's edge, with its window buttons left of the controls. + */ +html[data-window-controls]:not([dir="rtl"]) [data-window-row-right] > [data-composer-panel-head="right"], +html[data-window-controls][dir="rtl"] [data-window-row-right] > [data-composer-panel-head="left"] { + margin-right: calc(-1 * (var(--titlebar-right-inset) + 0.5rem)); + padding-right: calc(var(--titlebar-right-inset) + 0.5rem); +} + /* Something floating at the top end of a page with no row: next to the controls, lined up. */ html[data-window-controls]:not([dir="rtl"]) [data-window-beside-controls] { right: calc(var(--titlebar-right-inset) + 0.5rem); 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 && ( -
setNarrowSidebarOpen(false)} - /> - )} - {!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 && ( <>
- { 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} - /> -
+ {calendarSidebar}
- {!isNarrow && ( - { dragStartWidth.current = calSidebarWidth; setIsResizing(true); }} - onResize={(delta) => setCalSidebarWidth(Math.max(180, Math.min(400, dragStartWidth.current + delta)))} - onResizeEnd={() => { - setIsResizing(false); - localStorage.setItem("calendar-sidebar-width", String(calSidebarWidth)); - }} - onDoubleClick={() => { setCalSidebarWidth(256); localStorage.setItem("calendar-sidebar-width", "256"); }} - /> - )} + { dragStartWidth.current = calSidebarWidth; setIsResizing(true); }} + onResize={(delta) => setCalSidebarWidth(Math.max(180, Math.min(400, dragStartWidth.current + delta)))} + onResizeEnd={() => { + setIsResizing(false); + localStorage.setItem("calendar-sidebar-width", String(calSidebarWidth)); + }} + onDoubleClick={() => { setCalSidebarWidth(256); localStorage.setItem("calendar-sidebar-width", "256"); }} + /> )} diff --git a/components/contacts/__tests__/contacts-app.test.tsx b/components/contacts/__tests__/contacts-app.test.tsx index ab4c422ed..393b29bac 100644 --- a/components/contacts/__tests__/contacts-app.test.tsx +++ b/components/contacts/__tests__/contacts-app.test.tsx @@ -102,6 +102,48 @@ describe('ContactsApp', () => { expect(within(drawer()).getByText('tabs.all')).toBeInTheDocument(); }); + // The same drawer as Mail's folders (usability test 2026-11-04): it opened + // beside the app rail, ignored Escape and left the focus on the page. + it("opens the drawer from the window's edge, over the app rail and under the top bar", () => { + renderContacts(); + 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('takes the focus into the drawer, keeps Tab there and gives it back to the menu button on Escape', () => { + renderContacts(); + const menu = screen.getAllByRole('button', { name: 'open_categories' })[0]; + menu.focus(); + fireEvent.click(menu); + // The category on screen. + const current = within(drawer()).getByRole('button', { name: /tabs\.all/ }); + expect(document.activeElement).toBe(current); + 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('dims the whole window behind the drawer and closes it on a click there, back to the menu button', () => { + renderContacts(); + const menu = screen.getAllByRole('button', { name: 'open_categories' })[0]; + menu.focus(); + fireEvent.click(menu); + const scrim = screen.getByTestId('drawer-scrim'); + expect(scrim.className.split(/\s+/)).toEqual(expect.arrayContaining(['fixed', 'inset-0'])); + // A press on the scrim drops the focus to the page. + (document.activeElement as HTMLElement).blur(); + fireEvent.click(scrim); + expect(drawer()).toHaveAttribute('inert'); + expect(screen.queryByTestId('drawer-scrim')).toBeNull(); + expect(document.activeElement).toBe(menu); + }); + it("closes the drawer when something in it is picked, so it doesn't stay over the form", () => { renderContacts(); fireEvent.click(screen.getAllByRole('button', { name: 'open_categories' })[0]); diff --git a/components/contacts/contacts-app.tsx b/components/contacts/contacts-app.tsx index 70d00e408..dbbebf3d3 100644 --- a/components/contacts/contacts-app.tsx +++ b/components/contacts/contacts-app.tsx @@ -49,6 +49,7 @@ import { useIsEmbedded } from "@/hooks/use-is-embedded"; import { useIsFocusedProTab } from "@/hooks/use-pane-context"; import { useProMultiAccountContacts } from "@/hooks/use-pro-multi-account-contacts"; import { ResizeHandle } from "@/components/layout/resize-handle"; +import { EdgeDrawer } from "@/components/layout/edge-drawer"; import { useIsFullDesktop, useIsMobile } from "@/hooks/use-media-query"; import { useRefreshGesture } from "@/hooks/use-refresh-gesture"; import type { ContactCard, AddressBook, AddressBookRights } from "@/lib/jmap/types"; @@ -210,6 +211,7 @@ function ContactsAppContent({ linkSegments: routeSegments }: ContactsAppProps = // into a burger-toggled overlay. const isNarrow = !isFullDesktop; const [narrowSidebarOpen, setNarrowSidebarOpen] = useState(false); + const closeNarrowSidebar = useCallback(() => setNarrowSidebarOpen(false), []); useEffect(() => { if (!isNarrow) setNarrowSidebarOpen(false); }, [isNarrow]); // A new view (a form, a group, a contact) replaces whatever the drawer was for. useEffect(() => { setNarrowSidebarOpen(false); }, [view]); @@ -1285,6 +1287,60 @@ function ContactsAppContent({ linkSegments: routeSegments }: ContactsAppProps = } })(); + // The categories: beside the list on the full desktop, a drawer below it. + const contactsSidebar = ( + setCreatingAddressBook(true)) : undefined} + onImport={fromDrawer(() => setShowImportDialog(true))} + onEditGroup={fromDrawer(guard(handleEditGroupFromSidebar))} + onDeleteGroup={fromDrawer(handleDeleteGroupFromSidebar)} + onComposeGroup={fromDrawer(handleComposeGroupFromSidebar)} + onDropContacts={handleDropContacts} + onDropContactsToCategory={handleDropContactsToCategory} + onRenameAddressBook={client ? fromDrawer((book: AddressBook) => setRenamingAddressBook(book)) : undefined} + onShareAddressBook={client ? fromDrawer((book: AddressBook) => setSharingAddressBookId(book.id)) : undefined} + onSetDefaultAddressBook={client ? fromDrawer(async (book: AddressBook) => { + try { + await setDefaultAddressBook(client, book); + toast.success(t("address_books.default_updated")); + } catch { + toast.error(t("address_books.set_default_failed")); + } + }) : undefined} + onCreateContactInBook={fromDrawer(guard((book: AddressBook) => { + setDefaultBookIdForCreate(book.id); + setSelectedContact(null); + setView("create"); + }))} + onDeleteAddressBook={client ? fromDrawer(async (book: AddressBook) => { + const ok = await confirmDialog({ + title: t("address_books.delete_title"), + message: t("address_books.confirm_delete", { name: shownName.addressBook(book) }), + variant: "destructive", + confirmText: t("address_books.delete"), + }); + if (!ok) return; + try { + await removeAddressBook(client, book); + toast.success(t("address_books.deleted")); + } catch { + toast.error(t("address_books.delete_failed")); + } + }) : undefined} + onRenameKeyword={fromDrawer((kw: string) => setRenamingKeyword(kw))} + onDeleteKeyword={fromDrawer((kw: string) => void handleDeleteKeyword(kw))} + directoryCount={showDirectory ? directoryPrincipals.length : undefined} + multiAccountMode={multiAccountEnabled && accountClients.length > 1} + /> + ); + const mobileBackToList = () => { if (returnToEmail) { setReturnToEmail(false); @@ -1331,105 +1387,49 @@ function ContactsAppContent({ linkSegments: routeSegments }: ContactsAppProps = {inlineApp && ( )} - {/* Clips the closed drawer, so it never sits over the nav rail. */} + {/* Holds the drawer in a Pro pane and clips it there when closed. */}
- {/* Narrow-pane backdrop for the overlay categories sidebar */} - {isNarrow && narrowSidebarOpen && ( -
setNarrowSidebarOpen(false)} - /> + {/* Panel 1: the categories. Below the full desktop a drawer from the + window's edge, over the app rail, as Mail's folders. */} + {showListPanel && isNarrow && ( + + {contactsSidebar} + + )} + {showListPanel && !isNarrow && !isMobile && ( + <> +
+ {contactsSidebar} +
+ { sidebarDragStartWidth.current = sidebarWidth; setIsSidebarResizing(true); }} + onResize={(delta) => setSidebarWidth(Math.max(180, Math.min(400, sidebarDragStartWidth.current + delta)))} + onResizeEnd={() => { + setIsSidebarResizing(false); + localStorage.setItem("contacts-sidebar-width", String(sidebarWidth)); + }} + onDoubleClick={() => { setSidebarWidth(256); localStorage.setItem("contacts-sidebar-width", "256"); }} + /> + )} - {/* Panel 1: Categories sidebar (in-flow on desktop, overlay on narrow) */} - {showListPanel && (!isMobile || isNarrow) && ( - <> -
- setCreatingAddressBook(true)) : undefined} - onImport={fromDrawer(() => setShowImportDialog(true))} - onEditGroup={fromDrawer(guard(handleEditGroupFromSidebar))} - onDeleteGroup={fromDrawer(handleDeleteGroupFromSidebar)} - onComposeGroup={fromDrawer(handleComposeGroupFromSidebar)} - onDropContacts={handleDropContacts} - onDropContactsToCategory={handleDropContactsToCategory} - onRenameAddressBook={client ? fromDrawer((book: AddressBook) => setRenamingAddressBook(book)) : undefined} - onShareAddressBook={client ? fromDrawer((book: AddressBook) => setSharingAddressBookId(book.id)) : undefined} - onSetDefaultAddressBook={client ? fromDrawer(async (book: AddressBook) => { - try { - await setDefaultAddressBook(client, book); - toast.success(t("address_books.default_updated")); - } catch { - toast.error(t("address_books.set_default_failed")); - } - }) : undefined} - onCreateContactInBook={fromDrawer(guard((book: AddressBook) => { - setDefaultBookIdForCreate(book.id); - setSelectedContact(null); - setView("create"); - }))} - onDeleteAddressBook={client ? fromDrawer(async (book: AddressBook) => { - const ok = await confirmDialog({ - title: t("address_books.delete_title"), - message: t("address_books.confirm_delete", { name: shownName.addressBook(book) }), - variant: "destructive", - confirmText: t("address_books.delete"), - }); - if (!ok) return; - try { - await removeAddressBook(client, book); - toast.success(t("address_books.deleted")); - } catch { - toast.error(t("address_books.delete_failed")); - } - }) : undefined} - onRenameKeyword={fromDrawer((kw: string) => setRenamingKeyword(kw))} - onDeleteKeyword={fromDrawer((kw: string) => void handleDeleteKeyword(kw))} - directoryCount={showDirectory ? directoryPrincipals.length : undefined} - multiAccountMode={multiAccountEnabled && accountClients.length > 1} - /> -
- {!isNarrow && ( - { sidebarDragStartWidth.current = sidebarWidth; setIsSidebarResizing(true); }} - onResize={(delta) => setSidebarWidth(Math.max(180, Math.min(400, sidebarDragStartWidth.current + delta)))} - onResizeEnd={() => { - setIsSidebarResizing(false); - localStorage.setItem("contacts-sidebar-width", String(sidebarWidth)); - }} - onDoubleClick={() => { setSidebarWidth(256); localStorage.setItem("contacts-sidebar-width", "256"); }} - /> - )} - - )} {/* The list and the contact: the main content, after the sidebar. */} onSelectCategory("all")} + // Marked as the other categories are: the drawer opens on it. + aria-current={isAllActive ? "true" : undefined} className={cn( "w-full flex items-center gap-2 px-3 text-sm transition-colors min-h-8 pointer-coarse:min-h-11", isAllActive @@ -342,6 +344,7 @@ export function ContactsSidebar({ {directoryCount !== undefined && ( ); } +/** + * The button in the composer's header that brings a folded panel back (none + * on phones). An open panel's Hide button is in its head instead + * (ComposerPanelHead). + */ +export function ComposerPanelToggle({ + side, + mode, + name = null, + onToggle, + className, +}: { + side: ComposerSidebarSide; + mode: ComposerSidebarMode | null; + name?: string | null; + onToggle: () => void; + className?: string; +}) { + if (mode !== "folded") return null; + return ; +} + +/** + * The part of the composer's header row above an open panel, as wide as the + * panel: its Hide button at the panel's inner edge, and for the right panel + * whatever else ends the row (the window buttons, Close last), so they stay + * at the far end of the composer. On phones there are no panels, and no head. + */ +export function ComposerPanelHead({ + side, + mode, + width = COMPOSER_SIDEBAR_WIDTH, + name = null, + onToggle, + className, + childrenClassName, + children, +}: { + side: ComposerSidebarSide; + mode: ComposerSidebarMode | null; + width?: number; + name?: string | null; + onToggle: () => void; + /** Padding of the row it is part of. */ + className?: string; + /** The gap between what it holds besides Hide, as in the row it is part of. */ + childrenClassName?: string; + children?: ReactNode; +}) { + if (!isPanelOpen(mode)) return null; + const hide = ; + return ( +
+ {side === "right" && hide} +
+ {/* No gap of the head's own around Hide and the space: a 260 px panel in the desktop app has just enough room for the buttons. */} + {children &&
{children}
} + {side === "left" && hide} +
+ ); +} + const COMPOSER_HEADER = "[data-composer-header], [data-mv-compose-titlebar], [data-mv-compose-inline-bar]"; const COMPOSER_FOOTER = "[data-composer-footer]"; diff --git a/components/email/email-composer.tsx b/components/email/email-composer.tsx index 5527d7a10..f37e64b6b 100644 --- a/components/email/email-composer.tsx +++ b/components/email/email-composer.tsx @@ -92,7 +92,7 @@ import { useIdentityStore } from "@/stores/identity-store"; import { useProMultiAccountIdentities, stripCrossAccountIdentityPrefix } from "@/hooks/use-pro-multi-account-identities"; import { useAccountStore } from "@/stores/account-store"; import { useSettingsStore } from "@/stores/settings-store"; -import { ComposerPanelToggle, ComposerPluginSidebar, useComposerSidebars } from "./composer-plugin-sidebars"; +import { ComposerPanelHead, ComposerPanelToggle, ComposerPluginSidebar, isPanelOpen, useComposerSidebars } from "./composer-plugin-sidebars"; import { dragKindFromTypes } from "@/components/pro/pro-shell-drop"; import { useIsPaneScoped } from "@/hooks/use-pane-context"; import { ComposerSelectionMenu, useComposerSelectionMenu } from "./composer-selection-menu"; @@ -3621,13 +3621,28 @@ export function EmailComposer({ [pluginDraft, pluginSelection, pluginComposerId, pluginSidebars.focusRequests.right], ); - // The buttons that show and hide the plugin panels, in the header. - const leftPanelToggle = pluginSidebars.modes.left - ? pluginSidebars.toggle('left')} /> + // The plugin panels in the header row: a folded one's Show button, and an + // open one's head with its Hide button (see composer-plugin-sidebars.tsx). + const leftPanelToggle = pluginSidebars.modes.left === 'folded' + ? pluginSidebars.toggle('left')} /> : null; - const rightPanelToggle = pluginSidebars.modes.right - ? pluginSidebars.toggle('right')} /> + const rightPanelToggle = pluginSidebars.modes.right === 'folded' + ? pluginSidebars.toggle('right')} /> : null; + const rightPanelOpen = isPanelOpen(pluginSidebars.modes.right); + const panelHead = (side: 'left' | 'right', className: string, children?: React.ReactNode, childrenClassName?: string) => ( + pluginSidebars.toggle(side)} + className={className} + childrenClassName={childrenClassName} + > + {children} + + ); // The right-click menu on selected text, when a plugin put entries in it. const selectionMenu = useComposerSelectionMenu(); @@ -4737,6 +4752,86 @@ export function EmailComposer({ ); + // What ends the header row: the window buttons, Close last. With the right + // panel open they end its head instead, at the far end of the composer. + const windowButtons = ( + <> + {canMaximize && ( + + )} + {popOutButton(cn(phoneLayout ? "hidden md:grid" : "grid", "h-8 w-8 shrink-0 place-items-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground"), "w-4 h-4")} + {!closeBesideControls && composerCloseButton} + + ); + const mvInlineButtons = mvWindow && ( + <> + {mvWindow.popOut && ( + + )} + {popOutButton("grid h-8 w-8 shrink-0 place-items-center rounded-full text-muted-foreground hover:bg-muted hover:text-foreground", "h-4 w-4")} + + + ); + const mvWindowButtons = mvWindow && ( + <> + {mvWindow.state !== "minimized" && popOutButton("grid h-7 w-7 shrink-0 place-items-center rounded-full text-muted-foreground hover:bg-foreground/10 hover:text-foreground", "h-4 w-4")} + + + + + ); + // Files dropped on the header attach, as on the rest of the message. + const headerDropProps = { onDragEnter: handleDragEnter, onDragLeave: handleDragLeave, onDragOver: handleDragOver, onDrop: handleDrop }; + // `keepDraft`: the bin's discard, which deletes the draft once its Undo is // over, not here. const handleDiscardAndClose = ({ keepDraft = false }: { keepDraft?: boolean } = {}) => { @@ -5019,8 +5114,11 @@ export function EmailComposer({ data-testid="email-composer" // Edits made while the draft moves wouldn't move with it. inert={isPoppingOut || undefined} + // The header row on top, across the plugin panels too, so the window + // buttons and Close end the whole composer; panels and message below. + data-tour="composer" className={cn( - "flex h-full bg-background relative", + "flex flex-col h-full bg-background relative", className, // Over everything but dialogs (z-60) and toasts; below the desktop app's window controls. // At the folder sidebar's z-50 and after it in the page, so over it (compose-p2-5). @@ -5039,112 +5137,57 @@ export function EmailComposer({
{liveMessage && {liveMessage.text}}
- pluginSidebars.setSideWidth('left', w)} /> - {/* Right-side composer sidebar slot is rendered after the main content div below. */} -
- {/* Drag overlay */} - {isDraggingOver && ( -
-
- - {t('drop_files')} -
-
- )} {/* Header - mobile: clean bar with close/send, desktop: title bar. In Mountain View's window it is the window's title bar instead. */} {mvWindow?.variant === "inline" ? ( -
- {mode === 'replyAll' - ? - : mode === 'forward' - ? - : } -

- {mode === 'reply' ? t('reply') : mode === 'replyAll' ? t('reply_all') : mode === 'forward' ? t('forward') : t('new_message')} -

- {saveStatus === 'saving' && } - {leftPanelToggle} - {rightPanelToggle} - {mvWindow.popOut && ( - - )} - {popOutButton("grid h-8 w-8 place-items-center rounded-full text-muted-foreground hover:bg-muted hover:text-foreground", "h-4 w-4")} - +
+ {panelHead('left', 'px-1.5')} +
+ {mode === 'replyAll' + ? + : mode === 'forward' + ? + : } +

+ {mode === 'reply' ? t('reply') : mode === 'replyAll' ? t('reply_all') : mode === 'forward' ? t('forward') : t('new_message')} +

+ {saveStatus === 'saving' && } + {leftPanelToggle} + {rightPanelToggle} + {!rightPanelOpen && mvInlineButtons} +
+ {panelHead('right', 'ps-1.5 pe-1.5', mvInlineButtons, 'gap-2')}
) : mvWindow ? (
mvWindow.setState("normal") : undefined} + {...headerDropProps} > -

- {mode === 'reply' || mode === 'replyAll' || mode === 'forward' - ? (subject || t('new_message')) - : t('new_message')} -

- {saveStatus === 'saving' && } - {mvWindow.state !== "minimized" && leftPanelToggle} - {mvWindow.state !== "minimized" && rightPanelToggle} - {mvWindow.state !== "minimized" && popOutButton("grid h-7 w-7 place-items-center rounded-full text-muted-foreground hover:bg-foreground/10 hover:text-foreground", "h-4 w-4")} - - - + {mvWindow.state !== "minimized" && panelHead('left', 'px-1.5')} +
+

+ {mode === 'reply' || mode === 'replyAll' || mode === 'forward' + ? (subject || t('new_message')) + : t('new_message')} +

+ {saveStatus === 'saving' && } + {mvWindow.state !== "minimized" && leftPanelToggle} + {mvWindow.state !== "minimized" && rightPanelToggle} + {(mvWindow.state === "minimized" || !rightPanelOpen) && mvWindowButtons} +
+ {mvWindow.state !== "minimized" && panelHead('right', 'ps-1.5 pe-1.5', mvWindowButtons, 'gap-1')}
) : ( -
+
+ {panelHead('left', 'px-2')} +
{closeBesideControls && composerCloseButton} - {/* The left panel's button at the start, the right one's at the end: where each panel is. */} + {/* A folded panel's Show button where the panel goes: the left one's at the start, the right one's before the window buttons. */} {leftPanelToggle &&
{leftPanelToggle}
}
@@ -5214,23 +5257,31 @@ export function EmailComposer({ ))} {rightPanelToggle} - {canMaximize && ( - - )} - {popOutButton(cn(phoneLayout ? "hidden md:grid" : "grid", "h-8 w-8 place-items-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground"), "w-4 h-4")} - {!closeBesideControls && composerCloseButton} + {!rightPanelOpen && windowButtons} +
+ {panelHead('right', 'ps-1.5 pe-4', windowButtons, 'gap-3')}
)} + {/* The left panel, the message and the right panel, under the header. */} +
+ pluginSidebars.setSideWidth('left', w)} /> +
+ {/* Drag overlay */} + {isDraggingOver && ( +
+
+ + {t('drop_files')} +
+
+ )} {/* Fields + body. While pinFields holds, the fields sit outside the body's scroll container so From/To/Cc/Bcc/Subject stay reachable while scrolling long bodies, matching the pinned formatting toolbar @@ -6306,6 +6357,7 @@ export function EmailComposer({ )}
pluginSidebars.setSideWidth('right', w)} /> +
); diff --git a/components/files/__tests__/file-browser-shared-folders.test.tsx b/components/files/__tests__/file-browser-shared-folders.test.tsx index d39f33a08..b583abb93 100644 --- a/components/files/__tests__/file-browser-shared-folders.test.tsx +++ b/components/files/__tests__/file-browser-shared-folders.test.tsx @@ -366,6 +366,53 @@ describe('FileBrowser', () => { expect(drawer).not.toHaveAttribute('inert'); }); + // The same drawer as Mail's folders (usability test 2026-11-04): it opened + // beside the app rail with only the file list dimmed, ignored Escape and + // left the focus on the page. + it("opens the folder drawer from the window's edge, with the whole window dimmed", () => { + renderBrowser(); + const drawer = screen.getByTestId('files-sidebar-drawer'); + 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'); + tree(); + expect(screen.getByTestId('drawer-scrim').className.split(/\s+/)).toEqual(expect.arrayContaining(['fixed', 'inset-0'])); + }); + + it('takes the focus into the folder drawer, keeps Tab there and gives it back on Escape without clearing the search', () => { + renderBrowser(); + const drawer = screen.getByTestId('files-sidebar-drawer'); + const menu = screen.getByRole('button', { name: 'open_folder_tree' }); + fireEvent.change(screen.getAllByRole('searchbox')[0], { target: { value: 'notes' } }); + menu.focus(); + fireEvent.click(menu); + // The folder on screen. + expect(drawer.contains(document.activeElement)).toBe(true); + expect(document.activeElement).toHaveAttribute('aria-current', 'page'); + 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); + expect(screen.getAllByRole('searchbox')[0]).toHaveValue('notes'); + }); + + it('closes the folder drawer on a click on the dimmed window and gives the focus back to the menu button', () => { + renderBrowser(); + const drawer = screen.getByTestId('files-sidebar-drawer'); + const menu = screen.getByRole('button', { name: 'open_folder_tree' }); + menu.focus(); + fireEvent.click(menu); + // A press on the scrim drops the focus to the page. + (document.activeElement as HTMLElement).blur(); + fireEvent.click(screen.getByTestId('drawer-scrim')); + expect(drawer).toHaveAttribute('inert'); + expect(document.activeElement).toBe(menu); + }); + it("renames in a dialog that selects the name without its extension and closes on Escape", async () => { renderBrowser({ props: { selectedResources: new Set(['notes.txt']) } }); fireEvent.keyDown(window, { key: 'F2' }); diff --git a/components/files/file-browser.tsx b/components/files/file-browser.tsx index 07467e075..bd1c0d351 100644 --- a/components/files/file-browser.tsx +++ b/components/files/file-browser.tsx @@ -32,6 +32,8 @@ import { INTERNAL_DRAG_TYPE, isInternalDrag, readDraggedNames } from "@/componen import { ResizeHandle } from "@/components/layout/resize-handle"; import { AppMain } from "@/components/layout/app-landmarks"; import { useIsEmbedded } from "@/hooks/use-is-embedded"; +import { useMountainViewShell } from "@/hooks/use-mountain-view-shell"; +import { EdgeDrawer } from "@/components/layout/edge-drawer"; import { getDroppedFilesAndFolders } from "@/lib/webdav/drop-utils"; import { getFilePreviewKind } from "@/lib/file-preview"; import type { FileAppAction } from "@/lib/files-app-actions"; @@ -298,6 +300,7 @@ export function FileBrowser({ const isMobile = useIsMobile(); const touch = useMediaQuery("(pointer: coarse)") && isMobile; const [narrowSidebarOpen, setNarrowSidebarOpen] = useState(false); + const closeNarrowSidebar = useCallback(() => setNarrowSidebarOpen(false), []); useEffect(() => { if (!isNarrow) setNarrowSidebarOpen(false); }, [isNarrow]); useEffect(() => { setNarrowSidebarOpen(false); }, [currentPath]); // Anything picked in the drawer closes it (R7). @@ -844,6 +847,8 @@ export function FileBrowser({ return; } if (e.key === "Escape") { + // The folder drawer is the innermost layer; it closes itself (R8). + if (narrowSidebarOpen) return; // The details panel over the list closes first (innermost layer, R8). if (showDetails && isNarrow) toggleDetails(false); else if (searchQuery) setSearchQuery(""); @@ -906,7 +911,7 @@ export function FileBrowser({ return () => window.removeEventListener("keydown", handler); }, [ showNewFolder, showNewTextFile, renameTarget, renameFolder, shareTargetId, moveTarget, accountPickerMode, selectedList, singleSelected, inTrash, - showDetails, isNarrow, toggleDetails, + showDetails, isNarrow, toggleDetails, narrowSidebarOpen, selectAllVisible, onCopy, onCut, onPaste, clipboard, searchQuery, onClearSelection, deleteNames, openResource, focusedName, onToggleSelect, currentPath, navigateUp, viewMode, gridColumns, moveFocus, displayResources, ]); @@ -1107,6 +1112,8 @@ export function FileBrowser({ const tSidebar = useTranslations("sidebar"); const tShell = useTranslations("shell"); const isEmbedded = useIsEmbedded(); + // Mountain View's card holds the drawer, under its top bar. + const mvShell = useMountainViewShell(isEmbedded); useRegisterCommands(tSidebar("files"), [ { id: "upload-files", label: tMenu("files_upload_files"), icon: Upload, run: () => fileInputRef.current?.click(), when: () => canCreate }, { id: "upload-folder", label: tMenu("files_upload_folder"), icon: FolderUp, run: () => folderInputRef.current?.click(), when: () => canCreate }, @@ -1312,26 +1319,21 @@ export function FileBrowser({ } : null; return ( - // Clips the closed drawer, so it never sits over the nav rail. + // Holds the drawer in a Pro pane and clips it there when closed.
- {/* Folder sidebar: in flow on desktop, a drawer on narrow panes */} - {sidebar && isNarrow && narrowSidebarOpen && ( -
setNarrowSidebarOpen(false)} /> - )} + {/* Folder sidebar: in flow on the full desktop; below it a drawer from + the window's edge, over the app rail, as Mail's folders. */} {sidebar && (isNarrow ? ( -
{sidebar} -
+ ) : ( <>
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); + }); + + // Seen in the desktop app: with visibility in the opening transition the + // panel is still hidden in its first frame and refuses the focus. + it('is visible from its first frame when it opens, and hidden only after sliding out', () => { + render(); + const classes = () => screen.getByTestId('drawer').className.split(/\s+/); + expect(classes()).toContain('transition-[transform,visibility]'); + fireEvent.click(screen.getByText('menu')); + expect(classes()).toContain('transition-transform'); + expect(classes()).not.toContain('transition-[transform,visibility]'); + expect(classes()).not.toContain('invisible'); + }); + + 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/__tests__/sidebar-folded-rail-scroll.test.tsx b/components/layout/__tests__/sidebar-folded-rail-scroll.test.tsx new file mode 100644 index 000000000..484b666a7 --- /dev/null +++ b/components/layout/__tests__/sidebar-folded-rail-scroll.test.tsx @@ -0,0 +1,224 @@ +import { act, render, screen, fireEvent, cleanup } from '@testing-library/react'; +import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'; +import type { Mailbox } from '@/lib/jmap/types'; + +// The folded folder column (600 to 1024 px) of a mailbox with many folders, +// scrolled: shared accounts left only their headings' rules behind, stacked +// into a ladder of lines; the unread counter sat on the icon; one folder of +// one's own was a letter in a box; and the drawer a hover opened kept the +// column's scroll offset, so the hovered folder was somewhere else. + +vi.mock('@/components/plugins/plugin-slot', () => ({ PluginSlot: () => null })); +vi.mock('@/components/tour/tour-provider', () => ({ + useTour: () => ({ startTour: vi.fn(), resetTourCompletion: vi.fn(), activeTour: null, endTour: vi.fn(), registerStep: vi.fn() }), +})); +vi.mock('@/contexts/drag-drop-context', () => ({ + useDragDropContext: () => ({ isDragging: false }), +})); +vi.mock('@/hooks/use-mailbox-drop', () => ({ + useMailboxDrop: () => ({ dropHandlers: {}, isValidDropTarget: false, isInvalidDropTarget: false }), +})); +vi.mock('@/hooks/use-tag-drop', () => ({ + useTagDrop: () => ({ dropHandlers: {}, isValidDropTarget: false }), +})); +vi.mock('../account-switcher', () => ({ AccountSwitcher: () => null })); + +const { Sidebar } = await import('../sidebar'); +const { useAuthStore } = await import('@/stores/auth-store'); +const { useSettingsStore } = await import('@/stores/settings-store'); +const { useUIStore } = await import('@/stores/ui-store'); + +const box = (id: string, name: string, role: string | null, extra: Partial = {}) => ({ + id, name, role, parentId: null, totalEmails: 0, unreadEmails: 0, myRights: { mayAddItems: true }, ...extra, +}) as unknown as Mailbox; + +const shared = (id: string, name: string, role: string | null, extra: Partial = {}) => + box(`g1:${id}`, name, role, { originalId: id, accountId: 'g1', accountName: 'Sam Ortega', isShared: true, ...extra }); + +const own = [ + box('inbox', 'Inbox', 'inbox', { totalEmails: 120, unreadEmails: 9 }), + box('clients', 'Clients', null, { parentId: 'inbox', unreadEmails: 132 }), + box('trash', 'Trash', 'trash', { unreadEmails: 3 }), + box('news', 'Newsletters', null, { unreadEmails: 150 }), +]; +// A shared account without an inbox: two folders someone shared. +const sharedNoInbox = [shared('team', 'Team', null, { unreadEmails: 2 }), shared('board', 'Board', null, { unreadEmails: 1 })]; + +const nav = () => document.querySelector('[data-folder-nav]')!; +const drawer = () => document.querySelector('[data-folder-drawer]'); +const row = (key: string) => document.querySelector(`[data-rail-key="${key}"]`)!; +const railButtons = () => Array.from(nav().querySelectorAll('[data-testid="folder-row"] > button')); + +describe('the folded folder column with many folders', () => { + beforeEach(() => { + localStorage.clear(); + useAuthStore.setState({ activeAccountId: 'login-a', client: { getAccountId: () => 'me', getCapabilities: () => ({}) } } as never); + useSettingsStore.setState({ + hideAccountSwitcher: true, interfaceLayout: 'default', openOnHover: true, unreadCountStyle: 'count', + showSharedMailAccounts: true, hiddenSharedMailAccounts: {}, compactSharedMailboxes: false, + } as never); + useUIStore.setState({ sidebarCollapsed: true, compactSidebarExpanded: false } as never); + }); + afterEach(() => { + cleanup(); + vi.useRealTimers(); + vi.restoreAllMocks(); + useUIStore.setState({ sidebarCollapsed: false } as never); + }); + + it('draws one rule between sections, never two in a row', () => { + render(); + // Folders, Your folders, Shared (with its account inside), Tags. + const rules = nav().querySelectorAll('[data-rail-separator]'); + expect(rules).toHaveLength(2 + 1); + // Walk the column in order: something to click between any two rules. + const order = Array.from(nav().querySelectorAll('[data-rail-separator], [data-testid="folder-row"]')); + order.forEach((el, i) => { + if (i === 0) return; + const both = el.hasAttribute('data-rail-separator') && order[i - 1].hasAttribute('data-rail-separator'); + expect(both, `two rules in a row at ${i}`).toBe(false); + }); + }); + + it('lists a shared account as one item, which opens the drawer with it unfolded when it has no inbox', () => { + render(); + const item = row('shared-account-g1'); + expect(item.getAttribute('data-testid')).toBe('folder-row'); + const button = item.querySelector('button')!; + expect(button.getAttribute('title')).toBe('name_unread'); + expect(item.querySelector('[data-testid="folded-unread"]')?.textContent).toBe('3'); + fireEvent.click(button); + expect(drawer()).not.toBeNull(); + expect(screen.getByText('Team')).toBeTruthy(); + }); + + it('opens a shared account\'s inbox from its item, and marks it while one of its folders is open', () => { + const onMailboxSelect = vi.fn(); + const mailboxes = [...own, shared('in', 'Inbox', 'inbox', { unreadEmails: 4 }), ...sharedNoInbox]; + const { rerender } = render(); + fireEvent.click(row('shared-account-g1').querySelector('button')!); + expect(onMailboxSelect).toHaveBeenCalledWith('g1:in'); + rerender(); + expect(row('shared-account-g1').querySelector('[data-testid="folded-selected"]')).not.toBeNull(); + }); + + it('puts the counter at the icon\'s corner, beside the glyph, and says 99+ for more', () => { + render(); + const badge = row('trash').querySelector('[data-testid="folded-unread"]')!; + expect(badge.textContent).toBe('3'); + // On the 36px item, above the 16px icon's box, not inside it over the glyph. + expect(badge.parentElement!.tagName).toBe('BUTTON'); + expect(badge.parentElement!.className).toContain('h-9'); + expect(badge.className.split(/\s+/)).toEqual(expect.arrayContaining(['absolute', 'top-0', 'end-0', 'h-3'])); + expect(badge.className).not.toContain('ring-2'); + expect(row('news').querySelector('[data-testid="folded-unread"]')!.textContent).toBe('99+'); + }); + + it('gives every item a tooltip with its name and count', () => { + render(); + for (const button of railButtons()) { + const title = button.getAttribute('title'); + expect(title, button.outerHTML.slice(0, 120)).toBeTruthy(); + expect(title).toBe(button.getAttribute('aria-label')); + } + // With unread mail the name carries the count. + expect(row('inbox').querySelector('button')!.getAttribute('title')).toBe('name_unread'); + }); + + it('draws one folder of one\'s own as a plain folder, several with their first letter inside the folder', () => { + render(); + expect(row('news').querySelector('[data-testid="folder-initial"]')).toBeNull(); + expect(row('news').querySelector('svg')).not.toBeNull(); + cleanup(); + render(); + const letter = row('receipts').querySelector('[data-testid="folder-initial"]')!; + expect(letter.textContent).toBe('R'); + // Inside the folder glyph, an icon like the others, not a box of its own. + expect(letter.closest('svg')?.querySelector('path')).not.toBeNull(); + expect(letter.closest('svg')!.getAttribute('class')).toContain('w-4'); + }); + + it('marks the open folder with a bar at the edge and a filled item', () => { + render(); + // Over the filled item, not under it. + expect(row('trash').querySelector('[data-testid="folded-selected"]')!.className).toContain('z-10'); + expect(row('trash').querySelector('button')!.className).toContain('bg-accent'); + expect(row('inbox').querySelector('[data-testid="folded-selected"]')).toBeNull(); + expect(row('inbox').querySelector('button')!.className).not.toContain('bg-accent'); + }); + + it('scrolls on its own, never sideways, with a thin scrollbar', () => { + render(); + expect(nav().hasAttribute('data-folder-rail')).toBe(true); + expect(nav().className.split(/\s+/)).toEqual(expect.arrayContaining(['overflow-y-auto', 'overflow-x-hidden', 'min-h-0'])); + }); + + it('moves through the items with the arrows, Home and End', () => { + render(); + const buttons = railButtons().filter((b) => !(b as HTMLButtonElement).disabled); + buttons[0].focus(); + fireEvent.keyDown(buttons[0], { key: 'ArrowDown' }); + expect(document.activeElement).toBe(buttons[1]); + fireEvent.keyDown(buttons[1], { key: 'ArrowUp' }); + expect(document.activeElement).toBe(buttons[0]); + fireEvent.keyDown(buttons[0], { key: 'End' }); + expect(document.activeElement).toBe(buttons[buttons.length - 1]); + fireEvent.keyDown(buttons[buttons.length - 1], { key: 'Home' }); + expect(document.activeElement).toBe(buttons[0]); + }); + + describe('the drawer opened from the scrolled column', () => { + // jsdom has no layout: the list's items sit at fixed places in the + // content, further down in the longer tree of the drawer. + let scrollTop = 0; + const NAV_TOP = 100; + const place = (el: Element) => { + const key = (el as HTMLElement).dataset?.railKey; + if (key !== 'news') return null; + return drawer() ? 900 : 500; + }; + beforeEach(() => { + scrollTop = 0; + vi.spyOn(Element.prototype, 'getBoundingClientRect').mockImplementation(function (this: Element) { + // The list shows 600px; anything else is somewhere inside it. + const isNav = this.hasAttribute('data-folder-nav'); + const at = place(this); + const top = isNav ? NAV_TOP : at === null ? NAV_TOP + 10 : NAV_TOP + at - scrollTop; + const height = isNav ? 600 : 36; + return { top, bottom: top + height, left: 0, right: 48, width: 48, height, x: 0, y: top, toJSON: () => ({}) } as DOMRect; + }); + }); + const trackScroll = () => Object.defineProperty(nav(), 'scrollTop', { + configurable: true, + get: () => scrollTop, + set: (v: number) => { scrollTop = v; }, + }); + + it('puts the hovered item back under the pointer, and the column back where it was', () => { + vi.useFakeTimers(); + const { container } = render(); + trackScroll(); + scrollTop = 200; + const news = row('news'); + document.elementFromPoint = vi.fn(() => news.querySelector('button')); + // At 400 on screen in the column: 100 + 500 - 200. + fireEvent.mouseEnter(container.firstElementChild!, { clientX: 20, clientY: 410 }); + act(() => { vi.advanceTimersByTime(400); }); + expect(drawer()).not.toBeNull(); + // In the drawer it is 900 down the list: scrolled so it is at 400 again. + expect(scrollTop).toBe(600); + fireEvent.mouseLeave(container.firstElementChild!); + expect(drawer()).toBeNull(); + expect(scrollTop).toBe(200); + }); + + it('starts at the top when All folders opens it', () => { + render(); + trackScroll(); + scrollTop = 200; + fireEvent.click(screen.getByTestId('folded-all-folders')); + expect(drawer()).not.toBeNull(); + expect(scrollTop).toBe(0); + }); + }); +}); diff --git a/components/layout/__tests__/sidebar-folder-drawer.test.tsx b/components/layout/__tests__/sidebar-folder-drawer.test.tsx index 413d7316b..d6f603121 100644 --- a/components/layout/__tests__/sidebar-folder-drawer.test.tsx +++ b/components/layout/__tests__/sidebar-folder-drawer.test.tsx @@ -102,11 +102,15 @@ describe('the folded column\'s drawer (default layout)', () => { expect(inDrawer).toBe(docked); }); - it('mirrors the collapse arrows in RTL, where the drawer comes from the right', () => { + // RTL: globals.css mirrors the chevrons icons; a flip of their own as well would turn them back. + it('leaves the collapse arrows to the global RTL mirror, where the drawer comes from the right', () => { + const arrow = () => screen.getByTestId('sidebar-collapse').querySelector('svg')!.getAttribute('class') ?? ''; render(); - expect(screen.getByTestId('sidebar-collapse').querySelector('svg')!.getAttribute('class')).toContain('rtl:-scale-x-100'); + expect(arrow()).toMatch(/tabler-icon-chevrons-(left|right)/); + expect(arrow()).not.toMatch(/rtl:/); openFromAllFolders(); - expect(screen.getByTestId('sidebar-collapse').querySelector('svg')!.getAttribute('class')).toContain('rtl:-scale-x-100'); + expect(arrow()).toMatch(/tabler-icon-chevrons-(left|right)/); + expect(arrow()).not.toMatch(/rtl:/); }); it('keeps Tab and Shift+Tab inside while open', () => { diff --git a/components/layout/edge-drawer.tsx b/components/layout/edge-drawer.tsx new file mode 100644 index 000000000..04a42fac0 --- /dev/null +++ b/components/layout/edge-drawer.tsx @@ -0,0 +1,76 @@ +"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 ( +