An open source design system that's fully customizable and agent ready
TypeScript
fix(lab): Schedule's event popover shows no scrollbar when its content fits (#7062)
Cindy Zhang9acf2845a12b
diff --git a/packages/lab/src/Schedule/MonthlyView.tsx b/packages/lab/src/Schedule/MonthlyView.tsxindex b057db09ad..c4666539ab 100644--- a/packages/lab/src/Schedule/MonthlyView.tsx+++ b/packages/lab/src/Schedule/MonthlyView.tsx@@ -48,6 +48,7 @@ import {MonthEventPill,ScheduleFrame,ScheduleMonthTitle,+ SchedulePopoverBody,styles,} from './shared';import {useCurrentTime} from './useCurrentTime';@@ -278,16 +279,19 @@ function ScheduleMonthlyView(</div>{dayPopover.popover.render(openDay == null ? null : (- <MonthDayEvents- day={openDay}- events={eventsByDay.get(plainDateToISO(openDay)) ?? EMPTY_EVENTS}- />+ <SchedulePopoverBody+ label={`${formatFullDate(openDay, timezoneID, locale)} events`}>+ <MonthDayEvents+ day={openDay}+ events={eventsByDay.get(plainDateToISO(openDay)) ?? EMPTY_EVENTS}+ />+ </SchedulePopoverBody>),{placement: 'below',alignment: 'start',offset: spacingVars['--spacing-1'],- xstyle: [styles.eventPopover, layerAnimations.below],+ xstyle: layerAnimations.below,},)}</ScheduleFrame>diff --git a/packages/lab/src/Schedule/TimeGridView.tsx b/packages/lab/src/Schedule/TimeGridView.tsxindex f92be78e95..7b8dc1a3a6 100644--- a/packages/lab/src/Schedule/TimeGridView.tsx+++ b/packages/lab/src/Schedule/TimeGridView.tsx@@ -58,6 +58,7 @@ import {getEventCategory,getMinutesSinceStartOfDay,isEventInPast,+ SchedulePopoverBody,ScheduleTime,styles,} from './shared';@@ -656,12 +657,19 @@ export function TimeGridView({<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],- })}+ popover.render(+ openContent == null || openEvent == null ? null : (+ <SchedulePopoverBody label={`${openEvent.title} details`}>+ {openContent}+ </SchedulePopoverBody>+ ),+ {+ placement: 'below',+ alignment: 'start',+ offset: spacingVars['--spacing-1'],+ xstyle: layerAnimations.below,+ },+ )}</>);}diff --git a/packages/lab/src/Schedule/__tests__/ScheduleEventPopover.a11y.chromium.spec.ts b/packages/lab/src/Schedule/__tests__/ScheduleEventPopover.a11y.chromium.spec.tsindex 95d3ff684c..d1a4592e52 100644--- a/packages/lab/src/Schedule/__tests__/ScheduleEventPopover.a11y.chromium.spec.ts+++ b/packages/lab/src/Schedule/__tests__/ScheduleEventPopover.a11y.chromium.spec.ts@@ -7,7 +7,9 @@* 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+ * leave a null event read-only; keep the read-only story unchanged; show+ * no scrollbar on a popover whose content fits; and scroll long content+ * from the keyboard* @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.@@ -363,3 +365,140 @@ test('without the option the grid stays read-only', async ({page}) => {expect(reading.hiddenGrid).toBe(true);expect(reading.dialogs).toBe(0);});++test('an open popover whose content fits has no scroll overflow and shows no scrollbar', async ({+ page,+}) => {+ await openStory(evidence, page, POPOVER_STORY, WIDE);+ await page.getByRole('button', {name: /^Workshop,/}).click();+ const dialog = page.getByRole('dialog');+ await expect(dialog).toBeVisible();+ // Every box from the popover layer down to its content: none may scroll+ // when the content fits, so classic scrollbars never paint.+ const overflow = await dialog.evaluate(element => {+ const boxes: Element[] = [];+ for (+ let box: Element | null = element;+ box != null && box !== document.body;+ box = box.parentElement+ ) {+ boxes.push(box);+ }+ boxes.push(...element.querySelectorAll('*'));+ return boxes+ .filter(box => {+ const style = getComputedStyle(box);+ return /auto|scroll/.test(style.overflowY + style.overflowX);+ })+ .map(box => ({+ role: box.getAttribute('role'),+ block: box.scrollHeight - box.clientHeight,+ inline: box.scrollWidth - box.clientWidth,+ }));+ });+ await record(evidence, page, 'popover-no-overflow', POPOVER_STORY, 'ltr', {+ overflow,+ });+ for (const box of overflow) {+ expect(box, 'a scroller around fitting popover content').toEqual({+ ...box,+ block: 0,+ inline: 0,+ });+ }+});++test('long popover content scrolls from the keyboard: Tab reaches its named group, and PageDown and ArrowDown reach the end', async ({+ page,+}) => {+ await openStory(evidence, page, POPOVER_STORY, WIDE);+ await page.getByRole('button', {name: /^Workshop,/}).click();+ const dialog = page.getByRole('dialog');+ await expect(dialog).toBeVisible();+ // 120 lines of details: far taller than the viewport.+ await page.evaluate(() => {+ const details = document.querySelector('[data-event-details]');+ for (let line = 1; line <= 120; line += 1) {+ const paragraph = document.createElement('p');+ paragraph.textContent = `Line ${line}`;+ details?.append(paragraph);+ }+ });+ const region = dialog.getByRole('group', {name: 'Workshop details'});+ await expect(region).toHaveAttribute('tabindex', '0');+ // Focus is in the dialog; Tab reaches the scrolling group before the+ // hidden close.+ for (let presses = 0; presses < 3; presses += 1) {+ const inRegion = await region.evaluate(+ element => document.activeElement === element,+ );+ if (inRegion) {+ break;+ }+ await page.keyboard.press('Tab');+ }+ await expect(region).toBeFocused();+ const scroll = () =>+ region.evaluate(element => ({+ top: Math.round(element.scrollTop),+ max: element.scrollHeight - element.clientHeight,+ }));+ // Keyboard scrolling is smooth, so each press is followed until the region+ // settles; the key is pressed until a press no longer moves it.+ const settle = async () => {+ let last = -1;+ for (let frame = 0; frame < 40; frame += 1) {+ const {top} = await scroll();+ if (top === last) {+ return top;+ }+ last = top;+ await page.waitForTimeout(50);+ }+ return last;+ };+ const pressUntilStill = async (key: string) => {+ let top = await settle();+ for (let presses = 0; presses < 200; presses += 1) {+ await page.keyboard.press(key);+ const next = await settle();+ if (next === top) {+ break;+ }+ top = next;+ }+ return scroll();+ };+ const atStart = await scroll();+ const afterPageDown = await pressUntilStill('PageDown');+ await page.keyboard.press('Home');+ await settle();+ const afterHome = await scroll();+ const afterArrowDown = await pressUntilStill('ArrowDown');+ // The surface itself stays inside the viewport.+ const surface = await dialog.boundingBox();+ const viewportHeight = page.viewportSize()?.height ?? 0;+ await record(+ evidence,+ page,+ 'popover-keyboard-scroll',+ POPOVER_STORY,+ 'ltr',+ {+ atStart,+ afterPageDown,+ afterHome,+ afterArrowDown,+ surfaceBottom: surface == null ? null : surface.y + surface.height,+ viewportHeight,+ },+ );+ expect(atStart.max).toBeGreaterThan(1000);+ expect(atStart.top).toBe(0);+ expect(afterPageDown.top).toBeGreaterThanOrEqual(afterPageDown.max - 1);+ expect(afterHome.top).toBe(0);+ expect(afterArrowDown.top).toBeGreaterThanOrEqual(afterArrowDown.max - 1);+ expect((surface?.y ?? 0) + (surface?.height ?? 0)).toBeLessThanOrEqual(+ viewportHeight,+ );+});diff --git a/packages/lab/src/Schedule/shared.tsx b/packages/lab/src/Schedule/shared.tsxindex 0ff75d72ae..92baf88c79 100644--- a/packages/lab/src/Schedule/shared.tsx+++ b/packages/lab/src/Schedule/shared.tsx@@ -11,6 +11,7 @@import {type ReactNode} from 'react';import * as stylex from '@stylexjs/stylex';+import {useScrollableArea} from '@astryxdesign/core/hooks';import {getLocaleDirection, type Locale} from '@astryxdesign/core/i18n';import {borderVars,@@ -204,6 +205,34 @@ export function ScheduleTime({children}: {children: ReactNode}) {return <bdi dir={getLocaleDirection(locale)}>{children}</bdi>;}+/**+ * The content of a Schedule view's popover. Only the content scrolls, inside+ * the surface: the popover's hidden fallback close sits one pixel below the+ * surface, so a scroller around the whole popover would count that pixel as+ * overflow and paint a scrollbar on content that fits, and would clip the+ * surface's shadow. Taller content scrolls in a named group that joins the+ * tab order only while it overflows, so the keyboard reaches all of it; a+ * group, not a region, so no popover adds a landmark.+ */+export function SchedulePopoverBody({+ label,+ children,+}: {+ label: string;+ children: ReactNode;+}) {+ const {getViewportProps, getContentProps} = useScrollableArea({+ axis: 'block',+ keyboardAccess: {owner: 'viewport', label},+ });+ return (+ <div+ {...getViewportProps<HTMLDivElement>({xstyle: styles.eventPopoverBody})}>+ <div {...getContentProps<HTMLDivElement>()}>{children}</div>+ </div>+ );+}+export function EventPill({event,day,@@ -1265,16 +1294,13 @@ export const styles = stylex.create({':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',+ // The popover keeps to the viewport the way the Popover component does: it+ // never grows past the visible block size, minus the surface padding.+ eventPopoverBody: {maxBlockSize: stylex.firstThatWorks(- `calc(100dvb - 2 * ${spacingVars['--spacing-4']})`,- `calc(100vh - 2 * ${spacingVars['--spacing-4']})`,+ `calc(100dvb - 2 * ${spacingVars['--spacing-4']} - 2 * ${spacingVars['--spacing-3']})`,+ `calc(100vh - 2 * ${spacingVars['--spacing-4']} - 2 * ${spacingVars['--spacing-3']})`,),- 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