Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(calendar): keep month-end keyboard focus on a valid day (#9244)

dev-rb0707d75b57ce
diff --git a/apps/web/src/features/calendar-view/components/CalendarSidebar.test.tsx b/apps/web/src/features/calendar-view/components/CalendarSidebar.test.tsx
index de3d87817d..1688787a79 100644
--- a/apps/web/src/features/calendar-view/components/CalendarSidebar.test.tsx
+++ b/apps/web/src/features/calendar-view/components/CalendarSidebar.test.tsx
@@ -19,7 +19,7 @@ import { addDays, format } from 'date-fns';
import { createSignal } from 'solid-js';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import type { CalendarFocusOccurrence } from '../calendar-focus-target';
-import { TeamOooUpcomingList } from './CalendarSidebar';
+import { CalendarMiniCalendar, TeamOooUpcomingList } from './CalendarSidebar';
const requests = vi.hoisted(() => ({
teamOoo: vi.fn<() => Promise<TeamOutOfOfficeItem[]>>(),
@@ -71,6 +71,7 @@ const closeEventDetails = vi.fn(() => {
vi.mock('@app/features/calendar/components/CalendarViewContext', () => ({
useCalendarView: () => ({
+ displaySettings: { weekStartsOn: 1 },
selectedEvent,
selectedEventAnchor,
selectEvent,
@@ -80,7 +81,7 @@ vi.mock('@app/features/calendar/components/CalendarViewContext', () => ({
}),
}));
vi.mock('@app/features/calendar/components/CalendarPagerContext', () => ({
- useCalendarPager: () => ({ gotoDate }),
+ useCalendarPager: () => ({ activeDateInfo: () => undefined, gotoDate }),
}));
vi.mock('../calendar-focus-target', () => ({
useCalendarFocus: () => ({ focusOccurrence }),
@@ -139,9 +140,86 @@ afterEach(() => {
setSelectedEvent(undefined);
setSelectedEventAnchor(undefined);
setOverlayVisible(false);
+ vi.useRealTimers();
vi.clearAllMocks();
});
+describe('CalendarMiniCalendar', () => {
+ it.each([
+ {
+ date: new Date(2026, 9, 31),
+ direction: 'next',
+ target: new Date(2026, 10, 30),
+ },
+ {
+ date: new Date(2027, 0, 31),
+ direction: 'next',
+ target: new Date(2027, 1, 28),
+ },
+ {
+ date: new Date(2028, 0, 31),
+ direction: 'next',
+ target: new Date(2028, 1, 29),
+ },
+ {
+ date: new Date(2027, 2, 31),
+ direction: 'previous',
+ target: new Date(2027, 1, 28),
+ },
+ ])(
+ 'keeps keyboard navigation usable after browsing $direction from $date',
+ async ({ date, direction, target }) => {
+ vi.useFakeTimers({ toFake: ['Date'] });
+ vi.setSystemTime(date);
+ const user = userEvent.setup();
+ render(() => <CalendarMiniCalendar />);
+
+ await user.click(
+ screen.getByRole('gridcell', {
+ name: '31',
+ selected: true,
+ })
+ );
+ await user.click(
+ screen.getByRole('button', { name: `Go to ${direction} month` })
+ );
+ expect(gotoDate).toHaveBeenCalledTimes(1);
+ if (direction === 'previous') await user.tab();
+ await user.tab();
+
+ expect(document.activeElement).toBe(
+ screen.getByRole('gridcell', {
+ name: String(target.getDate()),
+ selected: false,
+ })
+ );
+ await user.keyboard('{ArrowLeft}{Enter}');
+ expect(gotoDate).toHaveBeenLastCalledWith(addDays(target, -1));
+ }
+ );
+ it('keeps keyboard month changes independent until a day is selected', async () => {
+ vi.useFakeTimers({ toFake: ['Date'] });
+ vi.setSystemTime(new Date(2027, 0, 31));
+ const user = userEvent.setup();
+ render(() => <CalendarMiniCalendar />);
+
+ await user.click(
+ screen.getByRole('gridcell', { name: '31', selected: true })
+ );
+ await user.keyboard('{PageDown}{ArrowRight}');
+
+ expect(gotoDate).toHaveBeenCalledTimes(1);
+ expect(
+ screen.getByRole('button', { name: 'Choose month' }).textContent
+ ).toContain('March 2027');
+ expect(document.activeElement).toBe(
+ screen.getByRole('gridcell', { name: '1', selected: false })
+ );
+ await user.keyboard('{Enter}');
+ expect(gotoDate).toHaveBeenLastCalledWith(new Date(2027, 2, 1));
+ });
+});
+
describe('TeamOooUpcomingList', () => {
it('keeps the selected row attached when the poll refetches', async () => {
requests.teamOoo.mockImplementation(async () => teamOooItems());
diff --git a/apps/web/src/features/calendar-view/components/CalendarSidebar.tsx b/apps/web/src/features/calendar-view/components/CalendarSidebar.tsx
index 68fc003842..91aaf4fd72 100644
--- a/apps/web/src/features/calendar-view/components/CalendarSidebar.tsx
+++ b/apps/web/src/features/calendar-view/components/CalendarSidebar.tsx
@@ -26,7 +26,7 @@ import CloseIcon from '@icon/system/regular/x.svg';
import { Key } from '@solid-primitives/keyed';
import { Button, Checkbox, cn, Calendar as MiniCalendar } from '@ui';
import { tourTarget } from '@ui/components/Tour';
-import { format } from 'date-fns';
+import { format, getDaysInMonth } from 'date-fns';
import { createMemo, createSignal, For, Match, Show, Switch } from 'solid-js';
import { CalendarCallSidebar } from '../calendar-call-sidebar';
import { useCalendarFocus } from '../calendar-focus-target';
@@ -40,7 +40,7 @@ import { CalendarCreateMenu } from './CalendarCreateMenu';
import { CalendarSearch } from './CalendarSearch';
import { ConnectCalendarsPromotion } from './ConnectCalendarsPromotion';
-function CalendarMiniCalendar() {
+export function CalendarMiniCalendar() {
const calendarView = useCalendarView();
const calendarPager = useCalendarPager();
const initialDate = new Date();
@@ -48,20 +48,32 @@ function CalendarMiniCalendar() {
const currentDate = createMemo(
() => calendarPager.activeDateInfo()?.view.calendar.getDate() ?? initialDate
);
+ const [focusedDay, setFocusedDay] = createSignal(currentDate());
const highlightedRange = createMemo(() => {
const dateInfo = calendarPager.activeDateInfo();
if (dateInfo?.view.type !== 'timeGridWeek') return undefined;
return { end: dateInfo.end, start: dateInfo.start };
});
- // Month browsing and keyboard focus stay local to the mini calendar.
+ // Keep focus local and clamp month-end dates so shorter months stay tabbable.
return (
<MiniCalendar
required
fixedWeeks
startOfWeek={calendarView.displaySettings.weekStartsOn}
value={currentDate()}
+ focusedDay={focusedDay()}
highlightedRange={highlightedRange()}
+ onMonthChange={(month) =>
+ setFocusedDay(
+ new Date(
+ month.getFullYear(),
+ month.getMonth(),
+ Math.min(focusedDay().getDate(), getDaysInMonth(month))
+ )
+ )
+ }
+ onFocusedDayChange={setFocusedDay}
onValueChange={(date) => date && calendarPager.gotoDate(date)}
/>
);
diff --git a/docs/agent-guide/calendar.md b/docs/agent-guide/calendar.md
index bcc719012f..bd353331e5 100644
--- a/docs/agent-guide/calendar.md
+++ b/docs/agent-guide/calendar.md
@@ -473,6 +473,8 @@ month arrows, the month picker, and keyboard focus changes do not move the main
calendar. Selecting a day navigates the main calendar without closing the narrow
layout's navigation overlay. Main calendar navigation updates the mini calendar's
selected day and week highlight without resetting the month being browsed.
+When browsing from a month's last day to a shorter month, keyboard focus stays
+on the shorter month's last day so Tab and arrow-key navigation remain usable.
Active Quick Calls you created, participated in, or were invited to appear above your
next five events (including ones in progress), whether or not they have call links.