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(web): close an open calendar event on outside click (#7147)

Will Hutchinson4343f6b239b8
diff --git a/apps/web/src/features/calendar-view/components/Page.tsx b/apps/web/src/features/calendar-view/components/Page.tsx
index 0807ed633f..41b8034506 100644
--- a/apps/web/src/features/calendar-view/components/Page.tsx
+++ b/apps/web/src/features/calendar-view/components/Page.tsx
@@ -24,6 +24,7 @@ import {
calendarEventTimeFromFullCalendar,
canEditCalendarEventTime,
} from '@app/features/calendar/utils/event-interaction';
+import { consumeSuppressedCalendarDateSelection } from '@app/features/calendar/utils/open-event-outside-press';
import {
scrollEventChipIntoView,
timeGridScroller,
@@ -265,6 +266,13 @@ export function Page(props: {
const updateEventTime = useUpdateCalendarEventMutation();
const handleSelect = (selection: DateSelectArg) => {
if (!isActive()) return;
+ // The press that closes open event details also hits the grid. FullCalendar
+ // selects on mouseup, after the details have already closed, so that
+ // gesture must not open a new event.
+ if (consumeSuppressedCalendarDateSelection()) {
+ selection.view.calendar.unselect();
+ return;
+ }
const calendar = firstWritableCalendar();
setSelectionColor(calendar?.color ?? DEFAULT_CALENDAR_SOURCE.color);
openEventComposer({
diff --git a/apps/web/src/features/calendar-view/components/SelectedEventDetails.tsx b/apps/web/src/features/calendar-view/components/SelectedEventDetails.tsx
index 953c6896d1..8d52e48a19 100644
--- a/apps/web/src/features/calendar-view/components/SelectedEventDetails.tsx
+++ b/apps/web/src/features/calendar-view/components/SelectedEventDetails.tsx
@@ -12,6 +12,7 @@ import {
eventEmailRecipients,
guestEmails,
} from '@app/features/calendar/utils/guest-emails';
+import { handleOpenEventOutsidePress } from '@app/features/calendar/utils/open-event-outside-press';
import { EventRsvpSection } from '@app/features/calendar-view/components/EventRsvpSection';
import { useOpenEventComposer } from '@app/features/calendar-view/components/use-open-event-composer';
import { useOpenEventEmail } from '@app/features/calendar-view/components/use-open-event-email';
@@ -466,20 +467,7 @@ function EventDetailsPopover(props: EventDetailsPopoverProps) {
<Layer depth={3}>
<Popover.Content
class="portal-scope z-modal max-w-[calc(100vw-2rem)] outline-none"
- onInteractOutside={(event) => {
- // FullCalendar and external calendar target controls select on
- // click (pointer release), so dismissing on pointer down would
- // briefly close the popover before navigation finishes.
- const target = event.detail.originalEvent.target;
- if (
- target instanceof Element &&
- (target.closest('.fc-event') !== null ||
- target.closest('[data-calendar-event-target-navigation]') !==
- null)
- ) {
- event.preventDefault();
- }
- }}
+ onInteractOutside={handleOpenEventOutsidePress}
onOpenAutoFocus={(event) => {
// Aims can arrive while the keyboard is elsewhere — arrow-key
// scanning in the inbox previews a calendar notification here,
diff --git a/apps/web/src/features/calendar/utils/open-event-outside-press.test.ts b/apps/web/src/features/calendar/utils/open-event-outside-press.test.ts
new file mode 100644
index 0000000000..d7289a2e74
--- /dev/null
+++ b/apps/web/src/features/calendar/utils/open-event-outside-press.test.ts
@@ -0,0 +1,171 @@
+// @vitest-environment jsdom
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import {
+ classifyOpenEventOutsidePress,
+ consumeSuppressedCalendarDateSelection,
+ handleOpenEventOutsidePress,
+} from './open-event-outside-press';
+
+// This jsdom build has no PointerEvent. The handler identifies primary
+// presses with `instanceof PointerEvent`, so the stand-in has to be global.
+if (typeof globalThis.PointerEvent === 'undefined') {
+ class PointerEventPolyfill extends MouseEvent {
+ pointerType: string;
+ constructor(
+ type: string,
+ init: MouseEventInit & { pointerType?: string } = {}
+ ) {
+ super(type, init);
+ this.pointerType = init.pointerType ?? 'mouse';
+ }
+ }
+ globalThis.PointerEvent =
+ PointerEventPolyfill as unknown as typeof PointerEvent;
+}
+
+function mountGrid() {
+ document.body.innerHTML = `
+ <div class="calendar-view">
+ <div class="fc">
+ <div id="slot" class="fc-timegrid-slot-lane"></div>
+ <a id="event" class="fc-event"><span id="event-label">Standup</span></a>
+ <div id="background" class="fc-bg-event fc-event"></div>
+ <a id="nav" data-navlink></a>
+ <div id="more" class="fc-popover"></div>
+ <button id="event-target" data-calendar-event-target-navigation></button>
+ </div>
+ </div>
+ <div class="fc">
+ <div id="foreign-slot" class="fc-timegrid-slot-lane"></div>
+ </div>
+ <button id="outside" type="button">Sidebar</button>
+ `;
+}
+
+function dispatchedPress(
+ target: Element,
+ init: PointerEventInit = { button: 0, pointerType: 'mouse' }
+) {
+ let action: ReturnType<typeof classifyOpenEventOutsidePress> | undefined;
+ let outsidePrevented = false;
+ let pointerPrevented = false;
+ const listener = (event: Event) => {
+ action = classifyOpenEventOutsidePress(event);
+ const originalPreventDefault = event.preventDefault.bind(event);
+ event.preventDefault = () => {
+ pointerPrevented = true;
+ originalPreventDefault();
+ };
+ handleOpenEventOutsidePress({
+ preventDefault: () => {
+ outsidePrevented = true;
+ },
+ detail: { originalEvent: event },
+ });
+ };
+ target.addEventListener('pointerdown', listener);
+ target.dispatchEvent(
+ new PointerEvent('pointerdown', {
+ bubbles: true,
+ cancelable: true,
+ ...init,
+ })
+ );
+ target.removeEventListener('pointerdown', listener);
+ return { action, outsidePrevented, pointerPrevented };
+}
+
+beforeEach(() => {
+ vi.useFakeTimers();
+});
+
+afterEach(() => {
+ document.dispatchEvent(new PointerEvent('pointerup', { bubbles: true }));
+ vi.runOnlyPendingTimers();
+ vi.useRealTimers();
+ consumeSuppressedCalendarDateSelection();
+ document.body.innerHTML = '';
+});
+
+describe('open event outside press', () => {
+ it('closes event details on an empty grid press without starting a new event', () => {
+ mountGrid();
+ const slot = document.getElementById('slot');
+ if (!slot) throw new Error('missing slot');
+
+ const result = dispatchedPress(slot);
+
+ expect(result.action).toBe('close-without-creating');
+ expect(result.outsidePrevented).toBe(false);
+ expect(result.pointerPrevented).toBe(true);
+ expect(consumeSuppressedCalendarDateSelection()).toBe(true);
+ expect(consumeSuppressedCalendarDateSelection()).toBe(false);
+ });
+
+ it('keeps the details open when the press is another event or an event target', () => {
+ mountGrid();
+ for (const id of ['event', 'event-label', 'background', 'event-target']) {
+ const target = document.getElementById(id);
+ if (!target) throw new Error(`missing ${id}`);
+ const result = dispatchedPress(target);
+ expect(result.action, id).toBe('keep-open');
+ expect(result.outsidePrevented, id).toBe(true);
+ expect(result.pointerPrevented, id).toBe(false);
+ expect(consumeSuppressedCalendarDateSelection(), id).toBe(false);
+ }
+ });
+
+ it('still closes for presses that do not create an event', () => {
+ mountGrid();
+ for (const id of ['nav', 'more', 'foreign-slot', 'outside']) {
+ const target = document.getElementById(id);
+ if (!target) throw new Error(`missing ${id}`);
+ const result = dispatchedPress(target);
+ expect(result.action, id).toBe('close');
+ expect(result.outsidePrevented, id).toBe(false);
+ expect(result.pointerPrevented, id).toBe(false);
+ }
+ });
+
+ it('does not cancel a touch or secondary press on empty grid time', () => {
+ mountGrid();
+ const slot = document.getElementById('slot');
+ if (!slot) throw new Error('missing slot');
+
+ expect(
+ dispatchedPress(slot, { button: 0, pointerType: 'touch' }).action
+ ).toBe('close');
+ expect(
+ dispatchedPress(slot, { button: 2, pointerType: 'mouse' }).action
+ ).toBe('close');
+ expect(consumeSuppressedCalendarDateSelection()).toBe(false);
+ });
+
+ it('suppresses only the selection reported by the dismissing gesture', () => {
+ vi.useFakeTimers();
+ mountGrid();
+ const slot = document.getElementById('slot');
+ if (!slot) throw new Error('missing slot');
+ dispatchedPress(slot);
+
+ document.dispatchEvent(new PointerEvent('pointerup', { bubbles: true }));
+ // mouseup, where FullCalendar reports the selection, follows pointerup.
+ expect(consumeSuppressedCalendarDateSelection()).toBe(true);
+
+ vi.runAllTimers();
+ expect(consumeSuppressedCalendarDateSelection()).toBe(false);
+ });
+
+ it('drops the suppression when the gesture ends without a selection', () => {
+ vi.useFakeTimers();
+ mountGrid();
+ const slot = document.getElementById('slot');
+ if (!slot) throw new Error('missing slot');
+ dispatchedPress(slot);
+
+ document.dispatchEvent(new PointerEvent('pointerup', { bubbles: true }));
+ vi.runAllTimers();
+
+ expect(consumeSuppressedCalendarDateSelection()).toBe(false);
+ });
+});
diff --git a/apps/web/src/features/calendar/utils/open-event-outside-press.ts b/apps/web/src/features/calendar/utils/open-event-outside-press.ts
new file mode 100644
index 0000000000..8f4d211039
--- /dev/null
+++ b/apps/web/src/features/calendar/utils/open-event-outside-press.ts
@@ -0,0 +1,121 @@
+/**
+ * Outside presses on open event details.
+ *
+ * The details popover is non-modal, so the press that dismisses it also lands
+ * on the grid. FullCalendar starts a date selection on mousedown and reports
+ * it on mouseup — after the popover has already closed on pointerdown — which
+ * opens a new event. Google Calendar consumes that press: the details close,
+ * and a later press is what creates.
+ */
+
+const DATE_SELECTION_BLOCKERS = [
+ '.fc-event:not(.fc-bg-event)',
+ '.fc-more-link',
+ 'a[data-navlink]',
+ '.fc-popover',
+].join(', ');
+
+export type OpenEventOutsidePress =
+ | 'keep-open'
+ | 'close'
+ | 'close-without-creating';
+
+/** Whether this grid press is one FullCalendar would turn into a new event. */
+export function pointerDownStartsCalendarDateSelection(
+ target: EventTarget | null
+): boolean {
+ if (!(target instanceof Element)) return false;
+ if (target.closest('.calendar-view .fc') === null) return false;
+ return target.closest(DATE_SELECTION_BLOCKERS) === null;
+}
+
+/**
+ * How an outside press on open event details should resolve.
+ *
+ * Event chips and explicit event targets keep the details up so the click can
+ * switch selection. A primary mouse/pen press on empty grid time closes the
+ * details and must not start a new event. Touch closes only — phones do not
+ * create from a grid press, and canceling the pointer would swallow the tap
+ * that dismisses the sheet.
+ */
+export function classifyOpenEventOutsidePress(
+ event: Event
+): OpenEventOutsidePress {
+ const target = event.target;
+ if (!(target instanceof Element)) return 'close';
+ if (
+ target.closest('.fc-event') !== null ||
+ target.closest('[data-calendar-event-target-navigation]') !== null
+ ) {
+ return 'keep-open';
+ }
+ if (
+ event instanceof PointerEvent &&
+ event.button === 0 &&
+ event.pointerType !== 'touch' &&
+ pointerDownStartsCalendarDateSelection(target)
+ ) {
+ return 'close-without-creating';
+ }
+ return 'close';
+}
+
+let suppressCalendarCreate = false;
+let clearSuppressTimer: ReturnType<typeof setTimeout> | undefined;
+let removePointerEndListener: (() => void) | undefined;
+
+/**
+ * Ignore the date selection this gesture is about to report.
+ *
+ * Cleared on the timer after pointerup, which is dispatched before mouseup, so
+ * the selection callback still observes the flag and a later press does not.
+ */
+export function armSuppressedCalendarDateSelection() {
+ suppressCalendarCreate = true;
+ removePointerEndListener?.();
+ const onPointerEnd = () => {
+ removePointerEndListener?.();
+ clearTimeout(clearSuppressTimer);
+ clearSuppressTimer = setTimeout(() => {
+ suppressCalendarCreate = false;
+ clearSuppressTimer = undefined;
+ }, 0);
+ };
+ document.addEventListener('pointerup', onPointerEnd, true);
+ document.addEventListener('pointercancel', onPointerEnd, true);
+ removePointerEndListener = () => {
+ document.removeEventListener('pointerup', onPointerEnd, true);
+ document.removeEventListener('pointercancel', onPointerEnd, true);
+ removePointerEndListener = undefined;
+ };
+}
+
+/** Whether the in-flight outside press should not open the event composer. */
+export function consumeSuppressedCalendarDateSelection() {
+ if (!suppressCalendarCreate) return false;
+ suppressCalendarCreate = false;
+ clearTimeout(clearSuppressTimer);
+ clearSuppressTimer = undefined;
+ return true;
+}
+
+/** Applies {@link classifyOpenEventOutsidePress} to a popover outside event. */
+export function handleOpenEventOutsidePress(event: {
+ preventDefault: () => void;
+ detail: { originalEvent: Event };
+}) {
+ const action = classifyOpenEventOutsidePress(event.detail.originalEvent);
+ if (action === 'keep-open') {
+ // FullCalendar and external calendar target controls select on click
+ // (pointer release), so dismissing on pointer down would briefly close
+ // the popover before navigation finishes.
+ event.preventDefault();
+ return;
+ }
+ if (action === 'close-without-creating') {
+ // Cancelling the pointerdown drops the compatibility mousedown, so
+ // FullCalendar never starts a date selection on this press.
+ event.detail.originalEvent.preventDefault();
+ armSuppressedCalendarDateSelection();
+ }
+}
diff --git a/docs/AGENT_GUIDE/surfaces.md b/docs/AGENT_GUIDE/surfaces.md
index 39c02b7302..3950a2c44a 100644
--- a/docs/AGENT_GUIDE/surfaces.md
+++ b/docs/AGENT_GUIDE/surfaces.md
@@ -953,6 +953,11 @@ name, per-calendar checkbox). Accounts start collapsed. Subscribed system calend
warning icon whose tooltip shows the provider error; the account keeps syncing its other
calendars and the badge clears on its own once that calendar syncs again.
+On desktop, clicking or dragging empty grid time opens the event composer.
+While an event's details are open, a press on empty grid time closes them and
+does not start a new event; the next press creates one. Clicking another event
+switches the open details.
+
The `New event` composer (also opened by dragging a range on the grid) has an `Event kind`
pill choosing between `Event` and `Out of office`. Picking `Out of office` hides the guests,
conferencing, and location pills and the description field (Google rejects them on this