An open source design system that's fully customizable and agent ready
TypeScript
fix(lab): Schedule paints a timed event that ends at midnight (#7079)
Cindy Zhang195c46579b4e
diff --git a/apps/storybook/stories/Schedule.stories.tsx b/apps/storybook/stories/Schedule.stories.tsxindex 7993585453..a1711ad9e9 100644--- a/apps/storybook/stories/Schedule.stories.tsx+++ b/apps/storybook/stories/Schedule.stories.tsx@@ -592,6 +592,56 @@ export const EventPopover: Story = {},};+const midnightEvents: CalendarEvent[] = [+ createEventFromISO({+ id: 'planning',+ title: 'Planning',+ category: 'Focus',+ start: '2026-05-13T17:00:00.000Z',+ end: '2026-05-13T18:00:00.000Z',+ }),+ createEventFromISO({+ id: 'late-sync',+ title: 'Late sync',+ category: 'Company',+ start: '2026-05-13T22:00:00.000Z',+ end: '2026-05-14T00:00:00.000Z',+ }),+ createEventFromISO({+ id: 'evening-review',+ title: 'Evening review',+ category: 'Design',+ start: '2026-05-14T20:00:00.000Z',+ end: '2026-05-15T00:00:00.000Z',+ }),+];++/**+ * Timed events that end exactly at midnight paint from their start to the+ * bottom of their day.+ */+export const EventEndingAtMidnight: Story = {+ render: () => {+ const [date, setDate] = useState<Instant>(FIXTURE_DATE);+ const view = useMemo(+ () => createScheduleWeeklyView({minHour: 16, maxHour: 24}),+ [],+ );++ return (+ <Schedule+ view={view}+ events={midnightEvents}+ 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/Schedule.test.tsx b/packages/lab/src/Schedule/Schedule.test.tsxindex af5dbb3aa2..f48ba41760 100644--- a/packages/lab/src/Schedule/Schedule.test.tsx+++ b/packages/lab/src/Schedule/Schedule.test.tsx@@ -661,6 +661,41 @@ describe('Schedule event popover', () => {return dialog as HTMLElement;}+ it('paints a timed event that ends exactly at midnight on the day it starts', () => {+ const lateSync = createEventFromISO({+ id: 'late',+ title: 'Late sync',+ category: 'Sync',+ start: '2026-05-13T22:00:00.000Z',+ end: '2026-05-14T00:00:00.000Z',+ });+ const {unmount} = renderWeek({minHour: 0, maxHour: 24}, [lateSync]);+ // Painted: a block outside the hidden read-only grid.+ const grid = screen.getByRole('grid', {name: 'Schedule time grid'});+ expect(+ screen+ .getAllByText('Late sync')+ .filter(element => !grid.contains(element)),+ ).toHaveLength(1);+ unmount();++ renderWeek({minHour: 0, maxHour: 24, renderPopover}, [lateSync]);+ const wednesday = screen.getByRole('group', {+ name: 'Wednesday, May 13, 2026',+ });+ expect(+ Array.from(wednesday.querySelectorAll('button')).map(button =>+ button.getAttribute('aria-label'),+ ),+ ).toEqual([+ 'Late sync, 10:00 PM - 12:00 AM, Sync, Wednesday, May 13, 2026',+ ]);+ const thursday = screen.getByRole('group', {+ name: 'Thursday, May 14, 2026',+ });+ expect(thursday.querySelectorAll('button')).toHaveLength(0);+ });+it('keeps the read-only grid and renders no button when the option is absent', () => {renderWeek();expect(eventButtons()).toEqual([]);diff --git a/packages/lab/src/Schedule/TimeGridView.tsx b/packages/lab/src/Schedule/TimeGridView.tsxindex 2cbf209085..75093d01de 100644--- a/packages/lab/src/Schedule/TimeGridView.tsx+++ b/packages/lab/src/Schedule/TimeGridView.tsx@@ -31,6 +31,7 @@ import {focusOutlineStyles,plainDateAddDays,plainDateFromInstant,+ plainDateIsAfter,plainDateIsBefore,plainDateIsEqual,plainDateToInstant,@@ -47,7 +48,6 @@ import {EventPill,eventPastSurfaceColorStyle,eventSurfaceColorStyle,- eventSpansPastDay,formatEventAccessibilityLabel,formatDayNumber,formatEventTime,@@ -921,7 +921,12 @@ function getTimedEventLayouts({const rawStart = plainDateIsBefore(startDate, day)? 0: getMinutesSinceStartOfDay(event.start, timezoneID);- const rawEnd = eventSpansPastDay(event, day, timezoneID)+ // An event that runs to midnight or past it fills the rest of the day;+ // ending exactly at midnight is the bottom of the column, not minute 0.+ const rawEnd = plainDateIsAfter(+ plainDateFromInstant(event.end, timezoneID),+ day,+ )? 24 * 60: getMinutesSinceStartOfDay(event.end, timezoneID);if (rawEnd <= minMinute || rawStart >= maxMinute) {diff --git a/packages/lab/src/Schedule/__tests__/ScheduleTimeGridMidnight.a11y.chromium.spec.ts b/packages/lab/src/Schedule/__tests__/ScheduleTimeGridMidnight.a11y.chromium.spec.tsnew file mode 100644index 0000000000..a6bf434b15--- /dev/null+++ b/packages/lab/src/Schedule/__tests__/ScheduleTimeGridMidnight.a11y.chromium.spec.ts@@ -0,0 +1,108 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file ScheduleTimeGridMidnight.a11y.chromium.spec.ts+ * @input The built Lab/Schedule EventEndingAtMidnight story in real Chromium+ * @output Receipted evidence that a timed event ending exactly at midnight+ * paints from its start to the bottom of its day column+ * @position Browser binding for `component:Schedule` FR8 (no event is+ * dropped) at the midnight boundary+ */++import {expect, test} from '@playwright/test';+import {+ finishEvidence,+ openStory,+ record,+ startEvidence,+ WIDE,+ type Evidence,+} from './timeGridProbe';++const STORY = 'lab-schedule--event-ending-at-midnight';+/** The story's hour window. */+const MIN_HOUR = 16;+const MAX_HOUR = 24;++let evidence: Evidence;+test.beforeAll(async () => {+ evidence = await startEvidence();+});+test.afterAll(async () => {+ await finishEvidence(evidence, 'midnight');+});++for (const [direction, globals] of [+ ['ltr', undefined],+ ['rtl', 'direction:rtl'],+] as const) {+ test(`an event ending at midnight paints to the bottom of its day (${direction})`, async ({+ page,+ }) => {+ await openStory(evidence, page, STORY, WIDE, globals);+ const blocks = await page.evaluate(+ titles =>+ titles.map(title => {+ const leaf = [+ ...document.querySelectorAll<HTMLElement>('.astryx-schedule *'),+ ].find(+ element =>+ element.children.length === 0 &&+ element.textContent?.trim() === title,+ );+ let block: HTMLElement | null = leaf ?? null;+ while (+ block != null &&+ getComputedStyle(block).position !== 'absolute'+ ) {+ block = block.parentElement;+ }+ const column = block?.parentElement;+ if (block == null || column == null) {+ return {title, painted: false};+ }+ const box = block.getBoundingClientRect();+ const day = column.getBoundingClientRect();+ return {+ title,+ painted: true,+ top: box.top - day.top,+ bottom: box.bottom - day.top,+ columnHeight: day.height,+ };+ }),+ ['Late sync', 'Evening review', 'Planning'],+ );+ await record(evidence, page, `midnight-${direction}`, STORY, direction, {+ blocks,+ });+ const hours = MAX_HOUR - MIN_HOUR;+ const read = (title: string) => {+ const block = blocks.find(reading => reading.title === title);+ expect(block?.painted, `${title} is painted`).toBe(true);+ if (block == null || !('columnHeight' in block)) {+ throw new Error(`${title} is not painted`);+ }+ return block as {top: number; bottom: number; columnHeight: number};+ };+ // An ordinary block from 17:00 to 18:00 gives the blocks' own insets.+ const planning = read('Planning');+ const hourHeight = planning.columnHeight / hours;+ const insetTop = planning.top - (17 - MIN_HOUR) * hourHeight;+ const insetBottom = (18 - MIN_HOUR) * hourHeight - planning.bottom;+ for (const [title, startHour] of [+ ['Late sync', 22],+ ['Evening review', 20],+ ] as const) {+ const block = read(title);+ expect(+ Math.abs(block.top - (startHour - MIN_HOUR) * hourHeight - insetTop),+ `${title} starts at ${startHour}:00`,+ ).toBeLessThanOrEqual(1);+ expect(+ Math.abs(block.columnHeight - block.bottom - insetBottom),+ `${title} ends at the bottom of its day`,+ ).toBeLessThanOrEqual(1);+ }+ });+}diff --git a/packages/lab/src/Schedule/shared.tsx b/packages/lab/src/Schedule/shared.tsxindex cd219549ab..4207c8cd99 100644--- a/packages/lab/src/Schedule/shared.tsx+++ b/packages/lab/src/Schedule/shared.tsx@@ -27,7 +27,6 @@ import {HStack} from '@astryxdesign/core/Stack';import {Heading, Text} from '@astryxdesign/core/Text';import {plainDateFromInstant,- plainDateIsAfter,plainDateIsBefore,plainDateToInstant,type PlainDate,@@ -582,17 +581,6 @@ export function clamp(value: number, min: number, max: number): number {return Math.min(max, Math.max(min, value));}-export function eventSpansPastDay(- event: CalendarInstantEvent,- day: PlainDate,- timezoneID: string,-): boolean {- return plainDateIsAfter(- plainDateFromInstant(Math.max(event.end - 1, event.start), timezoneID),- day,- );-}-export function isEventInPast(event: CalendarEvent,currentTime: Instant,