An open source design system that's fully customizable and agent ready
TypeScript
fix(lab): Schedule month chips lead with the title (#7107)
Cindy Zhang5a877f46baf5
diff --git a/packages/lab/src/Schedule/Schedule.doc.mjs b/packages/lab/src/Schedule/Schedule.doc.mjsindex c871d41de2..1c162b6edf 100644--- a/packages/lab/src/Schedule/Schedule.doc.mjs+++ b/packages/lab/src/Schedule/Schedule.doc.mjs@@ -88,7 +88,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. 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. In the month grid a week row shows at most three levels of chips; a busy day shows two and a "+N more" button that opens a popover listing every event of that day.',+ '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. In the month grid a week row shows at most three levels of chips; a busy day shows two and a "+N more" button that opens a popover listing every event of that day. A month chip leads with the title; the start time of a timed event follows it only when both fit.',},{name: 'Current time line',diff --git a/packages/lab/src/Schedule/Schedule.test.tsx b/packages/lab/src/Schedule/Schedule.test.tsxindex e493e35cee..aab4cb09af 100644--- a/packages/lab/src/Schedule/Schedule.test.tsx+++ b/packages/lab/src/Schedule/Schedule.test.tsx@@ -161,6 +161,29 @@ describe('Schedule', () => {).toBeInTheDocument();});+ it('leads each month chip with the title and gives an all-day chip no time', () => {+ // component:Schedule FR18: whether the time fits is layout, which jsdom+ // cannot measure; the order of title and time is checkable here.+ render(+ <Schedule+ view={createScheduleMonthlyView()}+ events={events}+ categories={categories}+ date={Date.UTC(2026, 4, 13)}+ focusDate={Date.UTC(2026, 4, 13)}+ timezoneID="UTC"+ />,+ );+ const chipText = (title: string) =>+ Array.from(document.querySelectorAll('[aria-hidden="true"] span')).find(+ chip =>+ chip.parentElement?.closest('span') == null &&+ chip.textContent?.includes(title),+ )?.textContent ?? null;+ expect(chipText('Visible sync')).toBe('Visible sync4:00 PM');+ expect(chipText('Design review')).toBe('Design review');+ });+it('renders monthly weekday headings at the configured headingLevel (default 3)', async () => {render(<Schedulediff --git a/packages/lab/src/Schedule/__tests__/ScheduleMonthChip.a11y.chromium.spec.ts b/packages/lab/src/Schedule/__tests__/ScheduleMonthChip.a11y.chromium.spec.tsnew file mode 100644index 0000000000..aae7b51143--- /dev/null+++ b/packages/lab/src/Schedule/__tests__/ScheduleMonthChip.a11y.chromium.spec.ts@@ -0,0 +1,191 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file ScheduleMonthChip.a11y.chromium.spec.ts+ * @input The built Lab/Schedule month-overflow story in real Chromium+ * @output Receipted evidence that a month chip leads with its title, shows+ * the start time beside it only when the whole title and the time fit, and+ * never lets the time truncate the title; all-day chips carry no time; in+ * LTR and RTL at a narrow and a wide width+ * @position Browser binding for `component:Schedule` FR18. jsdom has no+ * layout, so it cannot tell whether a time fits beside a title.+ */++import {expect, test, type Page} from '@playwright/test';+import {+ finishEvidence,+ openStory,+ record,+ startEvidence,+ WIDE,+ type Evidence,+} from './timeGridProbe';++const STORY = 'lab-schedule--month-overflow';+const NARROW_MONTH = {width: 800, height: 900};+// Titles the story paints as chips; the time is any "h:mm" run in a chip.+// A busy day paints its earliest events (FR15), so these are the timed chips+// the story paints.+const TIMED_TITLES = ['1:1', 'Standup', 'Planning', 'Design critique'] as const;+const ALL_DAY_TITLE = 'Design conference';++let evidence: Evidence;+test.beforeAll(async () => {+ evidence = await startEvidence();+});+test.afterAll(async () => {+ await finishEvidence(evidence, 'month-chip');+});++interface ChipReading {+ readonly title: string;+ readonly hasTime: boolean;+ /** The time paints on the chip's visible line. */+ readonly timeVisible: boolean;+ /** The title paints before the time in reading order. */+ readonly titleBeforeTime: boolean | null;+ /** The title is cut short (ellipsized). */+ readonly titleTruncated: boolean;+}++/**+ * Reads each chip by its text: the chip is the painted child of the month's+ * hidden event overlay that holds the title, the title and time are text+ * runs inside it, and the visible line is the chip's own content box.+ */+function readChips(+ page: Page,+ titles: ReadonlyArray<string>,+): Promise<ChipReading[]> {+ return page.evaluate(wanted => {+ const table = document.querySelector<HTMLElement>(+ '.astryx-schedule [role="table"], .astryx-schedule [role="grid"]',+ );+ const overlay = [+ ...(table?.querySelectorAll<HTMLElement>('[aria-hidden="true"]') ?? []),+ ].find(+ element =>+ getComputedStyle(element).position === 'absolute' &&+ element.children.length > 0,+ );+ const isRtl = getComputedStyle(table ?? document.body).direction === 'rtl';+ const textNodes = (root: Node): Text[] => {+ const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);+ const nodes: Text[] = [];+ for (+ let node = walker.nextNode();+ node != null;+ node = walker.nextNode()+ ) {+ nodes.push(node as Text);+ }+ return nodes;+ };+ const rectOf = (node: Text) => {+ const range = document.createRange();+ range.selectNodeContents(node);+ return range.getBoundingClientRect();+ };+ return wanted.map(title => {+ const chip = [...(overlay?.children ?? [])].find(element =>+ textNodes(element).some(node => node.textContent === title),+ );+ if (chip == null) {+ throw new Error(`no chip titled ${title}`);+ }+ const nodes = textNodes(chip);+ const titleNode = nodes.find(node => node.textContent === title);+ const timeNode = nodes.find(node =>+ /\d{1,2}:\d{2}/.test(node.textContent ?? ''),+ );+ const titleElement = titleNode?.parentElement;+ // The pill's padding box is the visible line.+ const pill = (chip.firstElementChild ?? chip) as HTMLElement;+ const pillRect = pill.getBoundingClientRect();+ const pillStyle = getComputedStyle(pill);+ const lineTop =+ pillRect.top + Number.parseFloat(pillStyle.borderTopWidth);+ const lineBottom =+ pillRect.bottom - Number.parseFloat(pillStyle.borderBottomWidth);+ const titleRect = titleNode == null ? null : rectOf(titleNode);+ const timeRect = timeNode == null ? null : rectOf(timeNode);+ const timeVisible =+ timeRect != null &&+ timeRect.top >= lineTop - 1 &&+ timeRect.bottom <= lineBottom + 1 &&+ timeRect.width > 0;+ return {+ title,+ hasTime: timeNode != null,+ timeVisible,+ titleBeforeTime:+ titleRect == null || timeRect == null || !timeVisible+ ? null+ : isRtl+ ? titleRect.left >= timeRect.right - 1+ : titleRect.right <= timeRect.left + 1,+ titleTruncated:+ titleElement == null+ ? false+ : titleElement.scrollWidth > titleElement.clientWidth + 1,+ };+ });+ }, titles);+}++function expectTitleFirst(chips: ReadonlyArray<ChipReading>) {+ for (const chip of chips) {+ expect(chip.hasTime, `${chip.title} carries a time`).toBe(true);+ if (chip.timeVisible) {+ expect(chip.titleBeforeTime, `${chip.title}: title before time`).toBe(+ true,+ );+ expect(+ chip.titleTruncated,+ `${chip.title}: a visible time never truncates the title`,+ ).toBe(false);+ }+ }+}++for (const [direction, globals] of [+ ['ltr', undefined],+ ['rtl', 'direction:rtl'],+] as const) {+ test(`month chips lead with the title and show the time only when both fit (${direction})`, async ({+ page,+ }) => {+ const readings: Record<string, ChipReading[]> = {};+ for (const [name, viewport] of [+ ['wide', WIDE],+ ['narrow', NARROW_MONTH],+ ] as const) {+ await openStory(evidence, page, STORY, viewport, globals);+ const chips = await readChips(page, TIMED_TITLES);+ readings[name] = chips;+ expectTitleFirst(chips);+ const [allDay] = await readChips(page, [ALL_DAY_TITLE]);+ expect(allDay.hasTime, 'an all-day chip carries no time').toBe(false);+ await record(+ evidence,+ page,+ `month-chip-${direction}-${name}`,+ STORY,+ direction,+ {+ chips,+ allDay,+ },+ );+ }+ // Both branches occur: a short title keeps its time at either width; a+ // longer one drops the time in a narrow column.+ expect(readings.wide.find(chip => chip.title === '1:1')?.timeVisible).toBe(+ true,+ );+ expect(+ readings.narrow.find(chip => chip.title === 'Design critique')+ ?.timeVisible,+ ).toBe(false);+ });+}diff --git a/packages/lab/src/Schedule/shared.tsx b/packages/lab/src/Schedule/shared.tsxindex 84d3031ffe..0ff75d72ae 100644--- a/packages/lab/src/Schedule/shared.tsx+++ b/packages/lab/src/Schedule/shared.tsx@@ -254,11 +254,38 @@ export function MonthEventPill({timezoneID: string;isPast?: boolean;}) {- const {categories, locale} = useScheduleContext();+ const {locale} = useScheduleContext();+ // A month chip shows its start time after the title (component:Schedule+ // FR18).+ return (+ <TitleFirstPill+ event={event}+ timeLabel={+ isDayEvent(event)+ ? null+ : formatEventStartTime(event, timezoneID, locale)+ }+ isPast={isPast}+ />+ );+}++/**+ * A pill that leads with the event's title; its time follows on the same+ * line only when the whole title and the time fit, and otherwise the title+ * shows alone, ellipsized.+ */+export function TitleFirstPill({+ event,+ timeLabel,+ isPast = false,+}: {+ event: CalendarEvent;+ timeLabel: string | null;+ isPast?: boolean;+}) {+ const {categories} = useScheduleContext();const category = getEventCategory(event, categories);- const timeLabel = isDayEvent(event)- ? null- : formatEventStartTime(event, timezoneID, locale);return (<span{...stylex.props(@@ -267,18 +294,23 @@ export function MonthEventPill({? eventPastSurfaceColorStyle(category.color): eventSurfaceColorStyle(category.color),)}>- {timeLabel != null && (- <Text type="supporting" color="inherit" xstyle={styles.eventTime}>- <ScheduleTime>{timeLabel}</ScheduleTime>+ <span {...stylex.props(styles.titleFirstLine)}>+ <Text+ type="supporting"+ color="inherit"+ weight="bold"+ xstyle={styles.titleFirstTitle}>+ {event.title}</Text>- )}- <Text- type="supporting"- color="inherit"- weight="bold"- xstyle={styles.eventTitle}>- {event.title}- </Text>+ {timeLabel != null && (+ <Text+ type="supporting"+ color="inherit"+ xstyle={styles.titleFirstTime}>+ <ScheduleTime>{timeLabel}</ScheduleTime>+ </Text>+ )}+ </span></span>);}@@ -906,6 +938,33 @@ export const styles = stylex.create({flexShrink: 0,opacity: 0.8,},+ // A chip that leads with its title is one line tall. Its title and time+ // wrap as a flex row, so the time drops to a second, clipped line whenever+ // the whole title and the time do not fit side by side: layout, not+ // script, decides whether the time shows (component:Schedule FR18, PR5).+ titleFirstLine: {+ display: 'flex',+ flexWrap: 'wrap',+ alignItems: 'baseline',+ columnGap: spacingVars['--spacing-1'],+ flexGrow: 1,+ minWidth: 0,+ blockSize: `calc(${typeScaleVars['--text-supporting-size']} * ${typeScaleVars['--text-supporting-leading']})`,+ overflow: 'hidden',+ },+ // Alone on the line, a long title shrinks and ellipsizes.+ titleFirstTitle: {+ minWidth: 0,+ maxWidth: '100%',+ overflow: 'hidden',+ textOverflow: 'ellipsis',+ whiteSpace: 'nowrap',+ },+ titleFirstTime: {+ flexShrink: 0,+ whiteSpace: 'nowrap',+ opacity: 0.8,+ },moreEvents: {...baseText,color: colorVars['--color-text-secondary'],