Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

feat(lab): Schedule week and day views open a popover they own from each event (#6929)

Cindy Zhangc3016f8f054b
diff --git a/apps/storybook/stories/Schedule.stories.tsx b/apps/storybook/stories/Schedule.stories.tsx
index e840579e73..7993585453 100644
--- a/apps/storybook/stories/Schedule.stories.tsx
+++ b/apps/storybook/stories/Schedule.stories.tsx
@@ -2,6 +2,7 @@
import {useMemo, useState} from 'react';
import type {Meta, StoryObj} from '@storybook/react';
+import {Text} from '@astryxdesign/core';
import {
Schedule,
createScheduleDayView,
@@ -547,6 +548,50 @@ export const OverlappingEvents: Story = {
},
};
+/**
+ * The week view owns a popover for its events: each event is a button that
+ * opens the system's standard Popover with the content the story returns.
+ * "Quick check-in" returns no content and stays read-only.
+ */
+export const EventPopover: Story = {
+ render: () => {
+ const [date, setDate] = useState<Instant>(FIXTURE_DATE);
+ const view = useMemo(
+ () =>
+ createScheduleWeeklyView({
+ minHour: 8,
+ maxHour: 18,
+ renderPopover: event =>
+ event.id === 'quarter' ? null : (
+ <div
+ data-event-details={event.id}
+ style={{display: 'flex', flexDirection: 'column', gap: 4}}>
+ <Text type="label" weight="bold">
+ {event.title}
+ </Text>
+ <Text type="supporting" color="secondary">
+ {event.category ?? 'No category'} · {event.id}
+ </Text>
+ </div>
+ ),
+ }),
+ [],
+ );
+
+ return (
+ <Schedule
+ view={view}
+ events={overlappingEvents}
+ categories={categories}
+ date={date}
+ focusDate={FIXTURE_DATE}
+ onChangeDate={setDate}
+ timezoneID={FIXTURE_TIMEZONE}
+ />
+ );
+ },
+};
+
export const ViewSelectorPlugin: Story = {
render: () => {
const views = useMemo(
diff --git a/packages/lab/src/Schedule/DayView.tsx b/packages/lab/src/Schedule/DayView.tsx
index add4a908e8..889c71587a 100644
--- a/packages/lab/src/Schedule/DayView.tsx
+++ b/packages/lab/src/Schedule/DayView.tsx
@@ -20,23 +20,20 @@ import {ScheduleMonthTitle, ScheduleFrame} from './shared';
import {TimeGridView} from './TimeGridView';
import {scheduleRangeToZonedDateTimeRange} from './zonedDateTime';
import type {
+ ScheduleTimeGridViewOptions,
PlainDate,
ScheduleView,
ScheduleViewComponentProps,
} from './types';
-export interface ScheduleDayViewOptions {
- minHour?: number;
- maxHour?: number;
- hourHeight?: number;
-}
+export type ScheduleDayViewOptions = ScheduleTimeGridViewOptions;
function ScheduleDayView({
options,
}: ScheduleViewComponentProps<ScheduleDayViewOptions>) {
const {events, date, focusDate, timezoneID, locale, range, isLoading} =
useScheduleContext();
- const {minHour = 0, maxHour = 24, hourHeight = 100} = options;
+ const {minHour = 0, maxHour = 24, hourHeight = 100, renderPopover} = options;
const rangeDate = date.toPlainDate();
const days = enumerateDates(range.startDate, range.endDate);
const titleLabel = plainDateFormat(
@@ -59,6 +56,7 @@ function ScheduleDayView({
maxHour={maxHour}
hourHeight={hourHeight}
label={titleLabel}
+ renderPopover={renderPopover}
/>
</ScheduleFrame>
);
@@ -68,10 +66,11 @@ export function createScheduleDayView({
minHour = 0,
maxHour = 24,
hourHeight = 100,
+ renderPopover,
}: ScheduleDayViewOptions = {}): ScheduleView<ScheduleDayViewOptions> {
return {
component: ScheduleDayView,
- options: {minHour, maxHour, hourHeight},
+ options: {minHour, maxHour, hourHeight, renderPopover},
getDateRange: date => {
const range = getDayDateRange({
date: date.toPlainDate(),
diff --git a/packages/lab/src/Schedule/Schedule.doc.mjs b/packages/lab/src/Schedule/Schedule.doc.mjs
index 80e34b8e62..998a5715fc 100644
--- a/packages/lab/src/Schedule/Schedule.doc.mjs
+++ b/packages/lab/src/Schedule/Schedule.doc.mjs
@@ -10,7 +10,7 @@ export const docs = {
usage: {
description:
- 'Schedule is a read-only calendar surface that renders events as a month grid, a day or week time grid, or a list grouped by day: the layout comes from a view object you pass in. It handles timezone-aware date math, paging between ranges, and async event loading, and exposes header slots that plugins fill with navigation controls. Use it to display an existing schedule; it has no event selection, creation, or editing affordances.',
+ "Schedule is a calendar surface that renders events as a month grid, a day or week time grid, or a list grouped by day: the layout comes from a view object you pass in. It handles timezone-aware date math, paging between ranges, and async event loading, and exposes header slots that plugins fill with navigation controls. Use it to display an existing schedule; build the week or day view with renderPopover to let people open an event's details in a popover the view manages. It has no event selection, creation, or editing affordances.",
bestPractices: [
{
guidance: true,
@@ -83,7 +83,7 @@ export const docs = {
name: 'Event',
required: false,
description:
- 'One pill (grid views) or row with a color dot (list view) per event, tinted by its category and dimmed once it is in the past.',
+ "One pill (grid views) or row with a color dot (list view) per event, tinted by its category and dimmed once it is in the past. In the day and week grids, events that happen at the same time share the column side by side, and when the view is built with renderPopover each event with content is a button that opens the view's popover.",
},
{
name: 'Current time line',
@@ -99,7 +99,7 @@ export const docs = {
name: 'view',
type: 'ScheduleView<Options>',
description:
- 'The view object that owns the layout and the date range each page covers. Build one with createScheduleMonthlyView, createScheduleWeeklyView, createScheduleDayView, or createScheduleListView; each factory takes its own options (weekStartsOn, minHour/maxHour/hourHeight, days).',
+ "The view object that owns the layout and the date range each page covers. Build one with createScheduleMonthlyView, createScheduleWeeklyView, createScheduleDayView, or createScheduleListView; each factory takes its own options (weekStartsOn, minHour/maxHour/hourHeight, days). The week and day factories also take renderPopover(event): return the content for an event and the view renders that event as a button that opens a popover it manages — one popover for the grid, named by the event title, with the system's standard surface, padding, Escape and light dismiss, and focus return; return null to leave an event read-only. The month and list views have no interaction option.",
required: true,
},
{
@@ -134,7 +134,7 @@ export const docs = {
name: 'onChangeDate',
type: '(date: Instant) => void',
description:
- "Called with the epoch milliseconds to render next when a pagination plugin pages backward or forward, or when Today is pressed. Paging preserves the time of day; Today passes the current time. This is the component's only callback; there is no event-level interaction.",
+ 'Called with the epoch milliseconds to render next when a pagination plugin pages backward or forward, or when Today is pressed. Paging preserves the time of day; Today passes the current time.',
},
{
name: 'timezoneID',
diff --git a/packages/lab/src/Schedule/Schedule.test.tsx b/packages/lab/src/Schedule/Schedule.test.tsx
index 91a6de35f2..af5dbb3aa2 100644
--- a/packages/lab/src/Schedule/Schedule.test.tsx
+++ b/packages/lab/src/Schedule/Schedule.test.tsx
@@ -2,6 +2,7 @@
import {describe, it, expect, vi} from 'vitest';
import {fireEvent, render, screen, waitFor} from '@testing-library/react';
+import {useMemo, useState} from 'react';
import {InternationalizationProvider} from '@astryxdesign/core/i18n';
import {createEventFromISO} from './CalendarEvent';
import {Schedule} from './Schedule';
@@ -587,3 +588,310 @@ describe('sortEvents', () => {
]);
});
});
+
+describe('Schedule event popover', () => {
+ const categories: ScheduleCategory[] = [
+ {label: 'Sync', color: 'blue'},
+ {label: 'Design', color: 'purple'},
+ ];
+ const events: CalendarEvent[] = [
+ createEventFromISO({
+ id: 'later',
+ title: 'Later sync',
+ category: 'Sync',
+ start: '2026-05-13T17:00:00.000Z',
+ end: '2026-05-13T17:30:00.000Z',
+ }),
+ createEventFromISO({
+ id: 'earlier',
+ title: 'Earlier sync',
+ category: 'Sync',
+ start: '2026-05-13T16:00:00.000Z',
+ end: '2026-05-13T16:30:00.000Z',
+ }),
+ createEventFromISO({
+ id: 'tuesday',
+ title: 'Tuesday sync',
+ category: 'Sync',
+ start: '2026-05-12T16:00:00.000Z',
+ end: '2026-05-12T16:30:00.000Z',
+ }),
+ createEventFromISO({
+ id: 'all-day',
+ title: 'Design review',
+ category: 'Design',
+ start: '2026-05-13',
+ end: '2026-05-13',
+ }),
+ ];
+ const renderPopover = (event: CalendarEvent) => (
+ <p>Details for {event.title}</p>
+ );
+
+ function renderWeek(
+ options: Parameters<typeof createScheduleWeeklyView>[0] = {},
+ eventSource: ReadonlyArray<CalendarEvent> = events,
+ ) {
+ return render(
+ <Schedule
+ view={createScheduleWeeklyView({minHour: 8, maxHour: 20, ...options})}
+ events={eventSource}
+ categories={categories}
+ date={Date.UTC(2026, 4, 13)}
+ focusDate={Date.UTC(2026, 4, 13)}
+ timezoneID="UTC"
+ />,
+ );
+ }
+
+ function eventButtons() {
+ return screen.queryAllByRole('button', {name: /sync|Design review/});
+ }
+
+ function dialogOf(button: HTMLElement): HTMLElement {
+ const controls = button.getAttribute('aria-controls');
+ expect(controls).toBeTruthy();
+ const layer = document.getElementById(controls ?? '');
+ expect(layer).not.toBeNull();
+ const dialog =
+ layer?.getAttribute('role') === 'dialog'
+ ? layer
+ : layer?.querySelector<HTMLElement>('[role="dialog"]');
+ expect(dialog).not.toBeNull();
+ return dialog as HTMLElement;
+ }
+
+ it('keeps the read-only grid and renders no button when the option is absent', () => {
+ renderWeek();
+ expect(eventButtons()).toEqual([]);
+ expect(
+ screen.getByRole('grid', {name: 'Schedule time grid'}),
+ ).toBeInTheDocument();
+ expect(screen.queryByRole('dialog')).toBeNull();
+ });
+
+ it('renders each event with content as a named popup button grouped by day', () => {
+ renderWeek({renderPopover});
+ expect(screen.queryByRole('grid')).toBeNull();
+ const allDay = screen.getByRole('group', {name: 'All-day events'});
+ const allDayButton = allDay.querySelector('button');
+ expect(allDayButton?.getAttribute('aria-label')).toBe(
+ 'Design review, all day, Design, Wednesday, May 13, 2026',
+ );
+ const wednesday = screen.getByRole('group', {
+ name: 'Wednesday, May 13, 2026',
+ });
+ expect(
+ Array.from(wednesday.querySelectorAll('button')).map(button =>
+ button.getAttribute('aria-label'),
+ ),
+ ).toEqual([
+ 'Earlier sync, 4:00 PM - 4:30 PM, Sync, Wednesday, May 13, 2026',
+ 'Later sync, 5:00 PM - 5:30 PM, Sync, Wednesday, May 13, 2026',
+ ]);
+ for (const button of eventButtons()) {
+ expect(button).toHaveAttribute('type', 'button');
+ expect(button).toHaveAttribute('aria-haspopup', 'dialog');
+ expect(button).toHaveAttribute('aria-expanded', 'false');
+ expect(button.getAttribute('aria-controls')).toBe(
+ eventButtons()[0].getAttribute('aria-controls'),
+ );
+ expect(button.closest('[aria-hidden="true"]')).toBeNull();
+ }
+ });
+
+ it('opens one popover named by the event, switches between events, and closes on Escape', () => {
+ renderWeek({renderPopover});
+ const earlier = screen.getByRole('button', {name: /^Earlier sync/});
+ const later = screen.getByRole('button', {name: /^Later sync/});
+
+ fireEvent.click(earlier);
+ expect(earlier).toHaveAttribute('aria-expanded', 'true');
+ expect(later).toHaveAttribute('aria-expanded', 'false');
+ const dialog = dialogOf(earlier);
+ expect(dialog).toHaveAttribute('aria-label', 'Earlier sync');
+ expect(dialog).toHaveTextContent('Details for Earlier sync');
+ // jsdom cannot show a native popover, so the dialog is queried by role
+ // attribute rather than through the accessibility tree.
+ expect(document.querySelectorAll('[role="dialog"]')).toHaveLength(1);
+
+ // A pointer press on another block closes the popover ahead of the
+ // browser's light dismiss; the click that follows opens the pressed block.
+ fireEvent.pointerDown(later);
+ expect(earlier).toHaveAttribute('aria-expanded', 'false');
+ fireEvent.click(later);
+ expect(earlier).toHaveAttribute('aria-expanded', 'false');
+ expect(later).toHaveAttribute('aria-expanded', 'true');
+ expect(dialogOf(later)).toHaveAttribute('aria-label', 'Later sync');
+ expect(dialogOf(later)).toHaveTextContent('Details for Later sync');
+ expect(document.querySelectorAll('[role="dialog"]')).toHaveLength(1);
+
+ fireEvent.keyDown(dialogOf(later), {key: 'Escape'});
+ expect(later).toHaveAttribute('aria-expanded', 'false');
+ expect(screen.queryByText('Details for Later sync')).toBeNull();
+ });
+
+ it('closes when the open block is clicked again or dismissed by the browser', () => {
+ renderWeek({renderPopover});
+ const earlier = screen.getByRole('button', {name: /^Earlier sync/});
+ fireEvent.pointerDown(earlier);
+ fireEvent.click(earlier);
+ expect(earlier).toHaveAttribute('aria-expanded', 'true');
+ // The press on the open block closes it, whether or not the browser's
+ // light dismiss already did.
+ fireEvent.pointerDown(earlier);
+ fireEvent.click(earlier);
+ expect(earlier).toHaveAttribute('aria-expanded', 'false');
+
+ fireEvent.pointerDown(earlier);
+ fireEvent.click(earlier);
+ expect(earlier).toHaveAttribute('aria-expanded', 'true');
+ // A browser light dismiss reaches the layer as a toggle to closed.
+ const layer = document.getElementById(
+ earlier.getAttribute('aria-controls') ?? '',
+ ) as HTMLElement;
+ const toggle = new Event('toggle');
+ Object.defineProperty(toggle, 'newState', {value: 'closed'});
+ fireEvent(layer, toggle);
+ expect(earlier).toHaveAttribute('aria-expanded', 'false');
+ });
+
+ it('leaves an event without content read-only but still exposed', () => {
+ renderWeek({
+ renderPopover: event =>
+ event.id === 'later' ? null : renderPopover(event),
+ });
+ expect(screen.queryByRole('button', {name: /^Later sync/})).toBeNull();
+ const wednesday = screen.getByRole('group', {
+ name: 'Wednesday, May 13, 2026',
+ });
+ const staticBlock = wednesday.querySelector(
+ '[aria-label^="Later sync"]',
+ ) as HTMLElement;
+ expect(staticBlock.tagName).toBe('DIV');
+ expect(staticBlock).not.toHaveAttribute('aria-haspopup');
+ expect(staticBlock.closest('[aria-hidden="true"]')).toBeNull();
+ expect(screen.getByRole('button', {name: /^Earlier sync/})).toBeVisible();
+ });
+
+ it('re-renders the open content with the event object of the same id and closes when it leaves', () => {
+ const {rerender} = renderWeek({renderPopover});
+ const view = createScheduleWeeklyView({
+ minHour: 8,
+ maxHour: 20,
+ renderPopover,
+ });
+ const earlier = screen.getByRole('button', {name: /^Earlier sync/});
+ fireEvent.click(earlier);
+ expect(dialogOf(earlier)).toHaveTextContent('Details for Earlier sync');
+
+ const renamed = events.map(event =>
+ event.id === 'earlier'
+ ? {...event, title: 'Earlier sync (moved)'}
+ : event,
+ );
+ rerender(
+ <Schedule
+ view={view}
+ events={renamed}
+ categories={categories}
+ date={Date.UTC(2026, 4, 13)}
+ focusDate={Date.UTC(2026, 4, 13)}
+ timezoneID="UTC"
+ />,
+ );
+ const renamedButton = screen.getByRole('button', {
+ name: /^Earlier sync \(moved\)/,
+ });
+ expect(renamedButton).toHaveAttribute('aria-expanded', 'true');
+ expect(dialogOf(renamedButton)).toHaveAttribute(
+ 'aria-label',
+ 'Earlier sync (moved)',
+ );
+ expect(dialogOf(renamedButton)).toHaveTextContent(
+ 'Details for Earlier sync (moved)',
+ );
+
+ rerender(
+ <Schedule
+ view={view}
+ events={renamed.filter(event => event.id !== 'earlier')}
+ categories={categories}
+ date={Date.UTC(2026, 4, 13)}
+ focusDate={Date.UTC(2026, 4, 13)}
+ timezoneID="UTC"
+ />,
+ );
+ expect(screen.queryByRole('button', {name: /^Earlier sync/})).toBeNull();
+ expect(screen.queryByText(/Details for Earlier sync/)).toBeNull();
+ expect(
+ screen.queryAllByRole('button', {name: /sync/, expanded: true}),
+ ).toEqual([]);
+ });
+
+ it('closes when the range is paged away from the open event', () => {
+ function Paged() {
+ const [date, setDate] = useState<Instant>(Date.UTC(2026, 4, 13));
+ const view = useMemo(
+ () =>
+ createScheduleWeeklyView({minHour: 8, maxHour: 20, renderPopover}),
+ [],
+ );
+ return (
+ <Schedule
+ view={view}
+ events={events}
+ categories={categories}
+ date={date}
+ onChangeDate={setDate}
+ timezoneID="UTC"
+ />
+ );
+ }
+ render(<Paged />);
+ const earlier = screen.getByRole('button', {name: /^Earlier sync/});
+ fireEvent.click(earlier);
+ expect(dialogOf(earlier)).toHaveTextContent('Details for Earlier sync');
+ fireEvent.click(screen.getByRole('button', {name: 'Next week'}));
+ expect(screen.queryByRole('button', {name: /^Earlier sync/})).toBeNull();
+ expect(screen.queryByText(/Details for Earlier sync/)).toBeNull();
+ });
+
+ it('leaves the month and list views read-only', () => {
+ const {rerender} = render(
+ <Schedule
+ view={createScheduleMonthlyView()}
+ events={events}
+ categories={categories}
+ date={Date.UTC(2026, 4, 13)}
+ timezoneID="UTC"
+ />,
+ );
+ expect(eventButtons()).toEqual([]);
+ rerender(
+ <Schedule
+ view={createScheduleListView()}
+ events={events}
+ categories={categories}
+ date={Date.UTC(2026, 4, 13)}
+ timezoneID="UTC"
+ />,
+ );
+ expect(eventButtons()).toEqual([]);
+ });
+
+ it('exposes the same option on the day view', () => {
+ render(
+ <Schedule
+ view={createScheduleDayView({minHour: 8, maxHour: 20, renderPopover})}
+ events={events}
+ categories={categories}
+ date={Date.UTC(2026, 4, 13)}
+ timezoneID="UTC"
+ />,
+ );
+ const earlier = screen.getByRole('button', {name: /^Earlier sync/});
+ fireEvent.click(earlier);
+ expect(dialogOf(earlier)).toHaveTextContent('Details for Earlier sync');
+ });
+});
diff --git a/packages/lab/src/Schedule/TimeGridView.tsx b/packages/lab/src/Schedule/TimeGridView.tsx
index 9290eab038..2cbf209085 100644
--- a/packages/lab/src/Schedule/TimeGridView.tsx
+++ b/packages/lab/src/Schedule/TimeGridView.tsx
@@ -11,15 +11,24 @@
*/
import {
+ useCallback,
useContext,
+ useEffect,
useLayoutEffect,
useMemo,
useRef,
+ useState,
+ type PointerEvent as ReactPointerEvent,
+ type ReactNode,
type UIEvent,
} from 'react';
import * as stylex from '@stylexjs/stylex';
import type {Locale} from '@astryxdesign/core/i18n';
+import {layerAnimations} from '@astryxdesign/core/Layer';
+import {usePopover} from '@astryxdesign/core/Popover';
+import {spacingVars} from '@astryxdesign/core/theme/tokens.stylex';
import {
+ focusOutlineStyles,
plainDateAddDays,
plainDateFromInstant,
plainDateIsBefore,
@@ -75,6 +84,7 @@ export function TimeGridView({
maxHour,
hourHeight,
label,
+ renderPopover,
}: {
days: PlainDate[];
events: ReadonlyArray<CalendarEvent>;
@@ -85,8 +95,11 @@ export function TimeGridView({
hourHeight: number;
/** Accessible name of the rendered range; names the scroll viewport. */
label: string;
+ /** Content of the view-owned event popover; absent keeps the grid read-only. */
+ renderPopover?: (event: CalendarEvent) => ReactNode;
}) {
const {categories, headingLevel, locale, range} = useScheduleContext();
+ const hasPopover = renderPopover != null;
const normalizedMinHour = Math.max(0, Math.min(23, Math.floor(minHour)));
const normalizedMaxHour = Math.max(
normalizedMinHour + 1,
@@ -211,32 +224,135 @@ export function TimeGridView({
}
};
+ // Event popover (component:Schedule FR11–FR12, DEC-1, DEC-5). The grid
+ // owns one popover and remembers which painted block opened it, by event id
+ // and day so a multi-day event's blocks open it separately. The popover is
+ // the system's standard Popover: dialog named by the event's title, modal,
+ // auto-focus, hidden fallback close, Escape and light dismiss, standard
+ // surface and padding. Content comes from the caller for the open event
+ // only; it re-renders with that event's current object while the event
+ // stays in range, and the popover closes when its block is no longer
+ // painted.
+ const [openBlock, setOpenBlock] = useState<{
+ eventID: string;
+ dayISO: string;
+ } | null>(null);
+ const openBlockRef = useRef(openBlock);
+ openBlockRef.current = openBlock;
+ const openEvent =
+ openBlock == null
+ ? null
+ : (events.find(event => event.id === openBlock.eventID) ?? null);
+ const popover = usePopover({
+ dialogLabel: openEvent?.title,
+ // Popover's own defaults, spelled out where the hook's differ.
+ padding: 3,
+ surfaceTarget: 'popover',
+ onHide: useCallback(() => {
+ setOpenBlock(null);
+ }, []),
+ });
+ const popoverRef = useRef(popover);
+ popoverRef.current = popover;
+ // A pointer press on a block while the popover is open would close it by
+ // the browser's light dismiss before the click arrives, and the layer then
+ // absorbs a show() from that same press. So the press itself decides: a
+ // press on another block closes the popover here, ahead of the browser,
+ // and the click that follows opens the pressed block; a press on the open
+ // block is remembered so its click ends closed, whichever of the two
+ // closed it. A key press starts a new gesture and forgets the press.
+ const openBlockAtPressRef = useRef<string | null>(null);
+ const handlePointerDownCapture = (
+ pointerEvent: ReactPointerEvent<HTMLDivElement>,
+ ) => {
+ const target = pointerEvent.target as Element | null;
+ const pressedKey =
+ target
+ ?.closest('[data-schedule-event-block]')
+ ?.getAttribute('data-schedule-event-block') ?? null;
+ const current = openBlockRef.current;
+ const currentKey =
+ current == null ? null : blockKeyOf(current.eventID, current.dayISO);
+ openBlockAtPressRef.current = pressedKey == null ? null : currentKey;
+ if (
+ pressedKey != null &&
+ currentKey != null &&
+ pressedKey !== currentKey &&
+ popover.isOpen
+ ) {
+ popover.hide();
+ }
+ };
+ const forgetPress = () => {
+ openBlockAtPressRef.current = null;
+ };
+ const toggleBlock = (
+ event: CalendarEvent,
+ dayISO: string,
+ button: HTMLButtonElement,
+ ) => {
+ const key = blockKeyOf(event.id, dayISO);
+ const openAtPress = openBlockAtPressRef.current;
+ openBlockAtPressRef.current = null;
+ const current = openBlockRef.current;
+ const isCurrent =
+ current != null && blockKeyOf(current.eventID, current.dayISO) === key;
+ if (openAtPress === key || (isCurrent && popover.isOpen)) {
+ if (popover.isOpen) {
+ popover.hide();
+ }
+ return;
+ }
+ setOpenBlock({eventID: event.id, dayISO});
+ popover.triggerRef(button);
+ popover.show();
+ };
+ // Blocks painted this render; the popover may stay open only for one of
+ // them.
+ const paintedBlockKeys = new Set<string>();
+ const openBlockKey =
+ openBlock == null ? null : blockKeyOf(openBlock.eventID, openBlock.dayISO);
+ let openContent: ReactNode = null;
+ useEffect(() => {
+ if (openBlockKey != null && !paintedBlockKeys.has(openBlockKey)) {
+ popoverRef.current.hide();
+ setOpenBlock(null);
+ }
+ });
+
const viewportProps = getViewportProps<HTMLDivElement>({
ref: viewportRef,
onScroll: rememberScroll,
+ onPointerDownCapture: handlePointerDownCapture,
+ onKeyDownCapture: forgetPress,
...stylex.props(styles.timeGridViewport, timeGridViewportScope),
});
const contentProps = getContentProps<HTMLDivElement>(
stylex.props(styles.timeGridContent(days.length)),
);
- // Everything painted below is decoration for sighted users; the hidden grid
- // above is what assistive technology reads. Each painted part is hidden on
- // its own, rather than the whole viewport, so the viewport itself can stay
- // a reachable, named keyboard scroll owner.
+ // Read-only: everything painted is decoration for sighted users and the
+ // hidden grid is what assistive technology reads. With renderPopover the
+ // painted events are the accessible representation themselves — buttons
+ // that open the popover, or static text for an event without content,
+ // grouped by day — so the hidden grid is not rendered twice over. Either
+ // way each decorative part is hidden on its own, never the viewport, so
+ // the viewport stays a reachable, named keyboard scroll owner.
return (
<>
- <TimeGridAccessibilityGrid
- allDayEvents={allDayEvents}
- categories={categories}
- days={days}
- events={instantEvents}
- focusDate={focusDate}
- hours={hours}
- locale={locale}
- timezoneID={timezoneID}
- timezoneLabel={timezoneLabel}
- />
+ {!hasPopover && (
+ <TimeGridAccessibilityGrid
+ allDayEvents={allDayEvents}
+ categories={categories}
+ days={days}
+ events={instantEvents}
+ focusDate={focusDate}
+ hours={hours}
+ locale={locale}
+ timezoneID={timezoneID}
+ timezoneLabel={timezoneLabel}
+ />
+ )}
<div {...stylex.props(styles.timeGridFrame)}>
<div {...viewportProps}>
<div {...contentProps}>
@@ -275,11 +391,14 @@ export function TimeGridView({
</Text>
</div>
<div
- aria-hidden
+ {...(hasPopover
+ ? {role: 'group', 'aria-label': 'All-day events'}
+ : {'aria-hidden': true})}
{...stylex.props(styles.allDayRow(allDayLevelCount))}>
{days.map((day, index) => (
<div
key={plainDateToISO(day)}
+ aria-hidden
{...stylex.props(
styles.allDayCell,
styles.allDaySubgridPlacement(index),
@@ -287,16 +406,11 @@ export function TimeGridView({
)}
/>
))}
- {allDaySegments.map(segment => (
- <div
- key={`${segment.event.id}:${segment.columnStart}`}
- {...stylex.props(
- styles.allDayEventSpan(
- segment.columnStart,
- segment.columnEnd,
- segment.level,
- ),
- )}>
+ {allDaySegments.map(segment => {
+ const day = days[segment.columnStart] ?? focusDate;
+ const dayISO = plainDateToISO(day);
+ const key = `${segment.event.id}:${segment.columnStart}`;
+ const pill = (
<EventPill
event={segment.event}
isPast={isEventInPast(
@@ -305,8 +419,70 @@ export function TimeGridView({
timezoneID,
)}
/>
- </div>
- ))}
+ );
+ const placement = styles.allDayEventSpan(
+ segment.columnStart,
+ segment.columnEnd,
+ segment.level,
+ );
+ const content = renderPopover?.(segment.event);
+ if (!hasPopover) {
+ return (
+ <div key={key} {...stylex.props(placement)}>
+ {pill}
+ </div>
+ );
+ }
+ if (content == null) {
+ return (
+ <div
+ key={key}
+ aria-label={formatEventButtonLabel(
+ segment.event,
+ day,
+ timezoneID,
+ categories,
+ locale,
+ )}
+ {...stylex.props(placement)}>
+ {pill}
+ </div>
+ );
+ }
+ const blockKey = blockKeyOf(segment.event.id, dayISO);
+ paintedBlockKeys.add(blockKey);
+ const isOpen = popover.isOpen && openBlockKey === blockKey;
+ if (isOpen) {
+ openContent = content;
+ }
+ return (
+ <button
+ key={key}
+ type="button"
+ aria-label={formatEventButtonLabel(
+ segment.event,
+ day,
+ timezoneID,
+ categories,
+ locale,
+ )}
+ aria-haspopup="dialog"
+ aria-expanded={isOpen}
+ aria-controls={popover.id}
+ data-schedule-event-block={blockKey}
+ onClick={domEvent =>
+ toggleBlock(segment.event, dayISO, domEvent.currentTarget)
+ }
+ {...stylex.props(
+ styles.eventButtonReset,
+ placement,
+ styles.eventButtonFocus,
+ focusOutlineStyles.focusVisible,
+ )}>
+ {pill}
+ </button>
+ );
+ })}
</div>
<div aria-hidden {...stylex.props(styles.timeLabels)}>
{hours.slice(1).map((hour, index) => (
@@ -331,7 +507,12 @@ export function TimeGridView({
return (
<div
key={plainDateToISO(day)}
- aria-hidden
+ {...(hasPopover
+ ? {
+ role: 'group',
+ 'aria-label': formatFullDate(day, timezoneID, locale),
+ }
+ : {'aria-hidden': true})}
{...stylex.props(
styles.timeColumn,
styles.dayColumnPlacement(index),
@@ -341,6 +522,7 @@ export function TimeGridView({
{hours.map((hour, hourIndex) => (
<div
key={hour}
+ aria-hidden
{...stylex.props(
styles.hourSlot,
hourIndex === hours.length - 1 && styles.hourSlotLast,
@@ -371,21 +553,20 @@ export function TimeGridView({
locale,
);
const category = getEventCategory(event, categories);
- return (
- <div
- key={event.id}
- {...stylex.props(
- styles.timedEvent,
- styles.timedEventPosition(
- clamp(top, 0, 100),
- clamp(height, 4, 100),
- (columnStart / columnCount) * 100,
- (columnSpan / columnCount) * 100,
- ),
- isEventInPast(event, currentTime, timezoneID)
- ? eventPastSurfaceColorStyle(category.color)
- : eventSurfaceColorStyle(category.color),
- )}>
+ const blockStyles = [
+ styles.timedEvent,
+ styles.timedEventPosition(
+ clamp(top, 0, 100),
+ clamp(height, 4, 100),
+ (columnStart / columnCount) * 100,
+ (columnSpan / columnCount) * 100,
+ ),
+ isEventInPast(event, currentTime, timezoneID)
+ ? eventPastSurfaceColorStyle(category.color)
+ : eventSurfaceColorStyle(category.color),
+ ];
+ const blockContent = (
+ <>
<Text
type="supporting"
color="inherit"
@@ -399,13 +580,68 @@ export function TimeGridView({
xstyle={styles.eventTime}>
{timeLabel}
</Text>
- </div>
+ </>
+ );
+ if (!hasPopover) {
+ return (
+ <div key={event.id} {...stylex.props(...blockStyles)}>
+ {blockContent}
+ </div>
+ );
+ }
+ const popoverContent = renderPopover(event);
+ const buttonLabel = formatEventButtonLabel(
+ event,
+ day,
+ timezoneID,
+ categories,
+ locale,
+ );
+ if (popoverContent == null) {
+ return (
+ <div
+ key={event.id}
+ aria-label={buttonLabel}
+ {...stylex.props(...blockStyles)}>
+ {blockContent}
+ </div>
+ );
+ }
+ const dayISO = plainDateToISO(day);
+ const blockKey = blockKeyOf(event.id, dayISO);
+ paintedBlockKeys.add(blockKey);
+ const isOpen =
+ popover.isOpen && openBlockKey === blockKey;
+ if (isOpen) {
+ openContent = popoverContent;
+ }
+ return (
+ <button
+ key={event.id}
+ type="button"
+ aria-label={buttonLabel}
+ aria-haspopup="dialog"
+ aria-expanded={isOpen}
+ aria-controls={popover.id}
+ data-schedule-event-block={blockKey}
+ onClick={domEvent =>
+ toggleBlock(event, dayISO, domEvent.currentTarget)
+ }
+ {...stylex.props(
+ styles.eventButtonReset,
+ ...blockStyles,
+ styles.eventButtonFocus,
+ focusOutlineStyles.focusVisible,
+ )}>
+ {blockContent}
+ </button>
);
},
)}
{plainDateIsEqual(day, currentDate) &&
currentTimeTop != null && (
<div
+ aria-hidden
{...stylex.props(
styles.currentTimeLine(currentTimeTop),
)}
@@ -418,6 +654,13 @@ export function TimeGridView({
</div>
<div aria-hidden {...stylex.props(styles.timeGridFocusRing)} />
</div>
+ {hasPopover &&
+ popover.render(openContent, {
+ placement: 'below',
+ alignment: 'start',
+ offset: spacingVars['--spacing-1'],
+ xstyle: [styles.eventPopover, layerAnimations.below],
+ })}
</>
);
}
@@ -548,6 +791,34 @@ function formatTimeGridAccessibilityCellLabel({
return `${label}. ${eventLabels.join('. ')}`;
}
+/** One painted block: an event on one day. Ids may contain any character. */
+function blockKeyOf(eventID: string, dayISO: string): string {
+ return `${dayISO}/${eventID}`;
+}
+
+/**
+ * A block exposed on its own, rather than inside a dated cell, carries the day
+ * in its name. The visible text — title, then time — leads the name, then the
+ * category and the full date.
+ */
+function formatEventButtonLabel(
+ event: CalendarEvent,
+ day: PlainDate,
+ timezoneID: string,
+ categories: ReadonlyArray<ScheduleCategory>,
+ locale: Locale,
+): string {
+ const category = getEventCategory(event, categories);
+ const timeLabel = isDayEvent(event)
+ ? 'all day'
+ : formatEventTime(event, day, timezoneID, locale);
+ return `${event.title}, ${timeLabel}, ${category.label}, ${formatFullDate(
+ day,
+ timezoneID,
+ locale,
+ )}`;
+}
+
function eventOverlapsHour(
event: CalendarInstantEvent,
day: PlainDate,
diff --git a/packages/lab/src/Schedule/WeeklyView.tsx b/packages/lab/src/Schedule/WeeklyView.tsx
index 091893d8d8..d5b61ec66b 100644
--- a/packages/lab/src/Schedule/WeeklyView.tsx
+++ b/packages/lab/src/Schedule/WeeklyView.tsx
@@ -24,15 +24,14 @@ import {TimeGridView} from './TimeGridView';
import {scheduleRangeToZonedDateTimeRange} from './zonedDateTime';
import type {
PlainDate,
+ ScheduleTimeGridViewOptions,
ScheduleView,
ScheduleViewComponentProps,
} from './types';
-export interface ScheduleWeeklyViewOptions {
+export interface ScheduleWeeklyViewOptions extends ScheduleTimeGridViewOptions {
+ /** Weekday the week starts on, 0 = Sunday. @default 0 */
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
- minHour?: number;
- maxHour?: number;
- hourHeight?: number;
}
function ScheduleWeeklyView({
@@ -40,7 +39,7 @@ function ScheduleWeeklyView({
}: ScheduleViewComponentProps<ScheduleWeeklyViewOptions>) {
const {events, focusDate, timezoneID, locale, range, isLoading} =
useScheduleContext();
- const {minHour = 0, maxHour = 24, hourHeight = 100} = options;
+ const {minHour = 0, maxHour = 24, hourHeight = 100, renderPopover} = options;
const days = enumerateDates(range.startDate, range.endDate);
const highlightedDate = focusDate.toPlainDate();
const titleLabel = formatWeekTitle(
@@ -70,6 +69,7 @@ function ScheduleWeeklyView({
maxHour={maxHour}
hourHeight={hourHeight}
label={titleLabel}
+ renderPopover={renderPopover}
/>
</ScheduleFrame>
);
@@ -80,10 +80,11 @@ export function createScheduleWeeklyView({
minHour = 0,
maxHour = 24,
hourHeight = 100,
+ renderPopover,
}: ScheduleWeeklyViewOptions = {}): ScheduleView<ScheduleWeeklyViewOptions> {
return {
component: ScheduleWeeklyView,
- options: {weekStartsOn, minHour, maxHour, hourHeight},
+ options: {weekStartsOn, minHour, maxHour, hourHeight, renderPopover},
getDateRange: date => {
const range = getWeekDateRange({
date: date.toPlainDate(),
diff --git a/packages/lab/src/Schedule/__tests__/ScheduleEventPopover.a11y.chromium.spec.ts b/packages/lab/src/Schedule/__tests__/ScheduleEventPopover.a11y.chromium.spec.ts
new file mode 100644
index 0000000000..95d3ff684c
--- /dev/null
+++ b/packages/lab/src/Schedule/__tests__/ScheduleEventPopover.a11y.chromium.spec.ts
@@ -0,0 +1,365 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file ScheduleEventPopover.a11y.chromium.spec.ts
+ * @input The built Lab/Schedule event-popover story in real Chromium
+ * @output Receipted evidence that, with renderPopover, events are keyboard
+ * reachable buttons whose popup attributes track one view-owned popover:
+ * open on Enter, Space, click, and tap; close on Escape and light dismiss
+ * with focus returned to the event; switch between events in one gesture;
+ * leave a null event read-only; and keep the read-only story unchanged
+ * @position Browser binding for `component:Schedule` FR11–FR14 and AR2–AR5.
+ * jsdom cannot show a native popover, return focus through it, paint a
+ * focus ring, or produce a touch tap.
+ */
+
+import {expect, test, type Page} from '@playwright/test';
+import pixelmatch from 'pixelmatch';
+// @ts-expect-error -- pngjs ships no declarations; runtime support is pinned.
+import {PNG} from 'pngjs';
+import {
+ finishEvidence,
+ openStory,
+ OVERLAPPING,
+ record,
+ startEvidence,
+ WIDE,
+ type Evidence,
+} from './timeGridProbe';
+
+const POPOVER_STORY = 'lab-schedule--event-popover';
+
+// Taps need a touch-capable context; nothing else here depends on it.
+test.use({hasTouch: true});
+
+let evidence: Evidence;
+test.beforeAll(async () => {
+ evidence = await startEvidence();
+});
+test.afterAll(async () => {
+ await finishEvidence(evidence, 'event-popover');
+});
+
+interface ButtonReading {
+ label: string | null;
+ expanded: string | null;
+ haspopup: string | null;
+ controls: string | null;
+ group: string | null | undefined;
+ insideHidden: boolean;
+}
+
+function readButton(page: Page, labelPrefix: string): Promise<ButtonReading> {
+ return page.evaluate(prefix => {
+ const button = [...document.querySelectorAll('button')].find(candidate =>
+ candidate.getAttribute('aria-label')?.startsWith(prefix),
+ );
+ if (button == null) {
+ throw new Error(`no event button starting with ${prefix}`);
+ }
+ return {
+ label: button.getAttribute('aria-label'),
+ expanded: button.getAttribute('aria-expanded'),
+ haspopup: button.getAttribute('aria-haspopup'),
+ controls: button.getAttribute('aria-controls'),
+ group: button.closest('[role="group"]')?.getAttribute('aria-label'),
+ insideHidden: button.closest('[aria-hidden="true"]') != null,
+ };
+ }, labelPrefix);
+}
+
+/** The open dialog as assistive technology sees it: visible, named, controlled. */
+function readDialog(page: Page) {
+ return page.evaluate(() => {
+ const dialogs = [
+ ...document.querySelectorAll<HTMLElement>('[role="dialog"]'),
+ ];
+ const open = dialogs.filter(dialog => {
+ const layer = dialog.closest<HTMLElement>('[popover]');
+ return layer != null && layer.matches(':popover-open');
+ });
+ const dialog = open[0];
+ return {
+ openCount: open.length,
+ label: dialog?.getAttribute('aria-label') ?? null,
+ layerID: dialog?.closest<HTMLElement>('[popover]')?.id ?? null,
+ details:
+ dialog
+ ?.querySelector('[data-event-details]')
+ ?.getAttribute('data-event-details') ?? null,
+ focusInside:
+ dialog != null && document.activeElement != null
+ ? dialog.contains(document.activeElement)
+ : false,
+ };
+ });
+}
+
+function activeLabel(page: Page) {
+ return page.evaluate(
+ () =>
+ document.activeElement?.getAttribute('aria-label') ??
+ document.activeElement?.getAttribute('role') ??
+ document.activeElement?.tagName.toLowerCase() ??
+ null,
+ );
+}
+
+test('Tab reaches event buttons that announce their popup, and Enter opens the popover for that event', async ({
+ page,
+}) => {
+ await openStory(evidence, page, POPOVER_STORY, WIDE);
+ const stops: string[] = [];
+ let reached = false;
+ for (let press = 0; press < 8 && !reached; press += 1) {
+ await page.keyboard.press('Tab');
+ const label = await activeLabel(page);
+ stops.push(label ?? 'other');
+ reached =
+ (await page.evaluate(
+ () =>
+ document.activeElement?.tagName === 'BUTTON' &&
+ document.activeElement.closest('[data-scroll-axis]') != null,
+ )) === true;
+ }
+ const first = await readButton(page, 'Offsite,');
+ expect(reached, `Tab reached an event button: ${stops.join(' → ')}`).toBe(
+ true,
+ );
+ expect(await activeLabel(page)).toBe(first.label);
+ expect(first).toMatchObject({
+ label: 'Offsite, all day, Company, Monday, May 11, 2026',
+ haspopup: 'dialog',
+ expanded: 'false',
+ group: 'All-day events',
+ insideHidden: false,
+ });
+ expect(first.controls).toBeTruthy();
+
+ await page.keyboard.press('Enter');
+ const afterEnter = await readButton(page, 'Offsite,');
+ const dialog = await readDialog(page);
+ await record(evidence, page, 'popover-keyboard-open', POPOVER_STORY, 'ltr', {
+ stops,
+ button: afterEnter,
+ dialog,
+ });
+ expect(afterEnter.expanded).toBe('true');
+ expect(dialog.openCount).toBe(1);
+ expect(dialog.label).toBe('Offsite');
+ expect(dialog.layerID).toBe(first.controls);
+ expect(dialog.details).toBe('offsite');
+ expect(dialog.focusInside).toBe(true);
+
+ // Escape closes it and focus returns to the event that opened it.
+ await page.keyboard.press('Escape');
+ await expect.poll(async () => (await readDialog(page)).openCount).toBe(0);
+ await expect
+ .poll(async () => (await readButton(page, 'Offsite,')).expanded)
+ .toBe('false');
+ const afterEscape = await readButton(page, 'Offsite,');
+ await record(evidence, page, 'popover-escape', POPOVER_STORY, 'ltr', {
+ button: afterEscape,
+ active: await activeLabel(page),
+ });
+ expect(afterEscape.expanded).toBe('false');
+ expect(await activeLabel(page)).toBe(first.label);
+
+ // Space opens it again, from the same button.
+ await page.keyboard.press('Space');
+ await expect.poll(async () => (await readDialog(page)).openCount).toBe(1);
+ expect((await readButton(page, 'Offsite,')).expanded).toBe('true');
+});
+
+test('click opens, clicking another event switches in one gesture, and light dismiss closes', async ({
+ page,
+}) => {
+ await openStory(evidence, page, POPOVER_STORY, WIDE);
+ const workshop = page.getByRole('button', {name: /^Workshop,/});
+ const coffee = page.getByRole('button', {name: /^Coffee chat,/});
+
+ await workshop.click();
+ await expect
+ .poll(async () => (await readDialog(page)).details)
+ .toBe('contain-long');
+ expect((await readButton(page, 'Workshop,')).expanded).toBe('true');
+
+ // Click another event while the first is open: one gesture, one dialog.
+ await coffee.click();
+ await expect
+ .poll(async () => (await readDialog(page)).details)
+ .toBe('contain-short');
+ const afterSwitch = {
+ workshop: await readButton(page, 'Workshop,'),
+ coffee: await readButton(page, 'Coffee chat,'),
+ dialog: await readDialog(page),
+ };
+ await record(
+ evidence,
+ page,
+ 'popover-switch',
+ POPOVER_STORY,
+ 'ltr',
+ afterSwitch,
+ );
+ expect(afterSwitch.workshop.expanded).toBe('false');
+ expect(afterSwitch.coffee.expanded).toBe('true');
+ expect(afterSwitch.dialog.openCount).toBe(1);
+ expect(afterSwitch.dialog.label).toBe('Coffee chat');
+
+ // Light dismiss: a click on the hour gutter, outside the dialog. The
+ // browser hides the popover first and reports it through an asynchronous
+ // toggle event, after which the button's expanded state follows.
+ await page.mouse.click(30, 700);
+ await expect.poll(async () => (await readDialog(page)).openCount).toBe(0);
+ await expect
+ .poll(async () => (await readButton(page, 'Coffee chat,')).expanded)
+ .toBe('false');
+ const afterDismiss = await readButton(page, 'Coffee chat,');
+ await record(evidence, page, 'popover-light-dismiss', POPOVER_STORY, 'ltr', {
+ button: afterDismiss,
+ });
+ expect(afterDismiss.expanded).toBe('false');
+
+ // A touch tap opens too.
+ await workshop.tap();
+ await expect
+ .poll(async () => (await readDialog(page)).details)
+ .toBe('contain-long');
+});
+
+test('an event without content stays read-only and the open popover closes when its event leaves', async ({
+ page,
+}) => {
+ await openStory(evidence, page, POPOVER_STORY, WIDE);
+ const quarter = await page.evaluate(() => {
+ const block = [...document.querySelectorAll('[aria-label]')].find(
+ candidate =>
+ candidate.getAttribute('aria-label')?.startsWith('Quick check-in,'),
+ );
+ return block == null
+ ? null
+ : {
+ tag: block.tagName.toLowerCase(),
+ haspopup: block.getAttribute('aria-haspopup'),
+ group: block.closest('[role="group"]')?.getAttribute('aria-label'),
+ insideHidden: block.closest('[aria-hidden="true"]') != null,
+ };
+ });
+ await record(evidence, page, 'popover-null-event', POPOVER_STORY, 'ltr', {
+ quarter,
+ });
+ expect(quarter).toMatchObject({
+ tag: 'div',
+ haspopup: null,
+ insideHidden: false,
+ });
+ expect(quarter?.group).toMatch(/May 1\d, 2026$/);
+
+ // Open an event, then page away: the popover closes and no dialog remains.
+ await page.getByRole('button', {name: /^Workshop,/}).click();
+ await expect.poll(async () => (await readDialog(page)).openCount).toBe(1);
+ const errors: string[] = [];
+ page.on('pageerror', error => errors.push(error.message));
+ page.on('console', message => {
+ if (message.type() === 'error') {
+ errors.push(message.text());
+ }
+ });
+ await page.getByRole('button', {name: 'Next week'}).click();
+ await expect.poll(async () => (await readDialog(page)).openCount).toBe(0);
+ const afterPaging = await page.evaluate(() => ({
+ workshopButtons: [...document.querySelectorAll('button')].filter(button =>
+ button.getAttribute('aria-label')?.startsWith('Workshop,'),
+ ).length,
+ expanded: document.querySelectorAll('[aria-expanded="true"]').length,
+ }));
+ await record(evidence, page, 'popover-event-left', POPOVER_STORY, 'ltr', {
+ afterPaging,
+ errors,
+ });
+ expect(afterPaging.workshopButtons).toBe(0);
+ expect(afterPaging.expanded).toBe(0);
+ expect(errors).toEqual([]);
+});
+
+test('a focused event button paints a ring and rises above its neighbours', async ({
+ page,
+}) => {
+ await openStory(evidence, page, POPOVER_STORY, WIDE);
+ const workshop = page.getByRole('button', {name: /^Workshop,/});
+ const box = await workshop.boundingBox();
+ expect(box).not.toBeNull();
+ const clip = {
+ x: (box?.x ?? 0) - 8,
+ y: (box?.y ?? 0) - 8,
+ width: (box?.width ?? 0) + 16,
+ height: (box?.height ?? 0) + 16,
+ };
+ const rest = await page.screenshot({clip});
+ await workshop.focus();
+ // Focus from script does not match :focus-visible; a key press does.
+ await page.keyboard.press('Shift');
+ const focused = await page.screenshot({clip});
+ const before = PNG.sync.read(rest) as {
+ width: number;
+ height: number;
+ data: Buffer;
+ };
+ const after = PNG.sync.read(focused) as {
+ width: number;
+ height: number;
+ data: Buffer;
+ };
+ const ringPixels = pixelmatch(
+ before.data,
+ after.data,
+ undefined,
+ before.width,
+ before.height,
+ {threshold: 0.1},
+ );
+ const style = await page.evaluate(() => {
+ const element = document.activeElement as HTMLElement;
+ const computed = getComputedStyle(element);
+ return {
+ outlineStyle: computed.outlineStyle,
+ outlineWidth: Number.parseFloat(computed.outlineWidth),
+ zIndex: computed.zIndex,
+ };
+ });
+ await record(evidence, page, 'popover-focus-ring', POPOVER_STORY, 'ltr', {
+ ringPixels,
+ style,
+ });
+ expect(style.outlineStyle).not.toBe('none');
+ expect(style.outlineWidth).toBeGreaterThan(0);
+ expect(style.zIndex).toBe('1');
+ expect(ringPixels).toBeGreaterThan(
+ ((box?.width ?? 0) + (box?.height ?? 0)) * 2,
+ );
+});
+
+test('without the option the grid stays read-only', async ({page}) => {
+ await openStory(evidence, page, OVERLAPPING, WIDE);
+ const reading = await page.evaluate(() => ({
+ eventButtons: [...document.querySelectorAll('.astryx-schedule button')]
+ .map(button => button.getAttribute('aria-label') ?? button.textContent)
+ .filter(name => !/week|Today/i.test(name ?? '')).length,
+ hiddenGrid:
+ document.querySelector('.astryx-schedule [role="grid"][aria-readonly]') !=
+ null,
+ dialogs: document.querySelectorAll('[role="dialog"]').length,
+ }));
+ await record(
+ evidence,
+ page,
+ 'read-only-unchanged',
+ OVERLAPPING,
+ 'ltr',
+ reading,
+ );
+ expect(reading.eventButtons).toBe(0);
+ expect(reading.hiddenGrid).toBe(true);
+ expect(reading.dialogs).toBe(0);
+});
diff --git a/packages/lab/src/Schedule/index.ts b/packages/lab/src/Schedule/index.ts
index 333e6b7d65..13bfcc5636 100644
--- a/packages/lab/src/Schedule/index.ts
+++ b/packages/lab/src/Schedule/index.ts
@@ -17,14 +17,8 @@ export {
createScheduleWeeklyView,
type ScheduleWeeklyViewOptions,
} from './WeeklyView';
-export {
- createScheduleDayView,
- type ScheduleDayViewOptions,
-} from './DayView';
-export {
- createScheduleListView,
- type ScheduleListViewOptions,
-} from './ListView';
+export {createScheduleDayView, type ScheduleDayViewOptions} from './DayView';
+export {createScheduleListView, type ScheduleListViewOptions} from './ListView';
export {ScheduleContext, useScheduleContext} from './context';
export {
defaultSchedulePlugins,
@@ -55,6 +49,7 @@ export type {
ScheduleHeaderContent,
SchedulePlugin,
SchedulePluginPosition,
+ ScheduleTimeGridViewOptions,
ScheduleView,
ScheduleViewBase,
ScheduleViewOptions,
diff --git a/packages/lab/src/Schedule/shared.tsx b/packages/lab/src/Schedule/shared.tsx
index 51ece65e72..cd219549ab 100644
--- a/packages/lab/src/Schedule/shared.tsx
+++ b/packages/lab/src/Schedule/shared.tsx
@@ -1082,6 +1082,48 @@ export const styles = stylex.create({
lineHeight: typeScaleVars['--text-supporting-leading'],
fontWeight: fontWeightVars['--font-weight-medium'],
},
+ // An event that opens the popover is a native button that keeps the block's
+ // own paint: the reset removes only what the user agent adds to a button.
+ // Block display lets an all-day pill fill the days its button spans; a
+ // timed block's own flex display wins over it.
+ eventButtonReset: {
+ appearance: 'none',
+ display: 'block',
+ // A button grid item would otherwise size to its content.
+ justifySelf: 'stretch',
+ margin: 0,
+ padding: 0,
+ borderWidth: 0,
+ borderStyle: 'none',
+ backgroundColor: 'transparent',
+ color: 'inherit',
+ font: 'inherit',
+ textAlign: 'start',
+ cursor: {
+ default: 'pointer',
+ ':is(:disabled,[aria-disabled="true"])': 'default',
+ },
+ },
+ // A focused block rises above its neighbours inside the isolated column so
+ // its ring is never clipped by a later sibling; nothing outside the column
+ // can see the value.
+ eventButtonFocus: {
+ zIndex: {
+ default: null,
+ ':focus-visible': 1,
+ },
+ },
+ // The event popover keeps to the viewport the way the Popover component
+ // does: it never grows past the visible block size, and scrolls inside
+ // when its content is taller.
+ eventPopover: {
+ boxSizing: 'border-box',
+ maxBlockSize: stylex.firstThatWorks(
+ `calc(100dvb - 2 * ${spacingVars['--spacing-4']})`,
+ `calc(100vh - 2 * ${spacingVars['--spacing-4']})`,
+ ),
+ overflowY: 'auto',
+ },
// Blocks in one overlap cluster split the column into equal tracks and never
// overlap, so they carry no z-index of their own; the 2px insets keep the
// same gutter a lone block has at the column's edges.
diff --git a/packages/lab/src/Schedule/types.ts b/packages/lab/src/Schedule/types.ts
index 1b95af31ea..4fcb3ec7e3 100644
--- a/packages/lab/src/Schedule/types.ts
+++ b/packages/lab/src/Schedule/types.ts
@@ -41,6 +41,31 @@ export interface ScheduleRange {
export type ScheduleViewOptions = object;
+/**
+ * Options the week and day views share: they paint the same time grid of
+ * timed blocks and all-day pills, so they take the same hour window and the
+ * same event popover.
+ */
+export interface ScheduleTimeGridViewOptions {
+ /** First hour drawn, 0–23. @default 0 */
+ minHour?: number;
+ /** Hour the grid ends at, 1–24, kept above `minHour`. @default 24 */
+ maxHour?: number;
+ /** Height of one hour in pixels. @default 100 */
+ hourHeight?: number;
+ /**
+ * Content of the popover the view opens from an event. The view renders
+ * each event with content as a native button and owns the popover it
+ * opens: one popover for the grid, named by the event's title, with the
+ * system's standard surface, padding, dismissal, and focus return. Called
+ * during render for every painted event block, so keep it pure and cheap,
+ * like a table cell renderer. Return `null` for an event that has nothing
+ * to open: that block stays read-only. When the option is absent the whole
+ * grid is read-only.
+ */
+ renderPopover?: (event: CalendarEvent) => ReactNode;
+}
+
export interface ScheduleViewComponentProps<
Options extends ScheduleViewOptions = ScheduleViewOptions,
> {