Skip to content

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

TypeScript

fix(BottomSheet): the open sheet's dialog places its panel with a flex row, not a grid (#8534)

Christopher Chedeau15f97c44fb57
diff --git a/.changeset/bottom-sheet-flex-host.md b/.changeset/bottom-sheet-flex-host.md
new file mode 100644
index 0000000000..6763da617c
--- /dev/null
+++ b/.changeset/bottom-sheet-flex-host.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] BottomSheet: the open sheet's dialog places its panel with a flex row instead of a grid. In desktop WebKit, measured in Playwright, an update inside an open sheet lays out faster; the iOS simulator showed no difference. A percentage `height` (for example `'50%'`) now takes that share of the screen at the bottom edge; before, a short sheet was cut short and a long one hung from the top of the screen.
+
+@vjeux
diff --git a/apps/storybook/stories/BottomSheetA11y.stories.tsx b/apps/storybook/stories/BottomSheetA11y.stories.tsx
new file mode 100644
index 0000000000..02d48b7450
--- /dev/null
+++ b/apps/storybook/stories/BottomSheetA11y.stories.tsx
@@ -0,0 +1,69 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file BottomSheetA11y.stories.tsx
+ * @input A hug-height BottomSheet with overflowing content placed directly in
+ * its content box, as plain text and as block children
+ * @output One checked-in story per case for the browser accessibility lane;
+ * excluded from the visual matrix
+ * @position Browser fixtures for BottomSheetScrollEnd.a11y.browser.spec.ts:
+ * the content box's block-end padding stays in the scroll range. Every
+ * long BottomSheet story wraps its content in a Section, which escapes that
+ * padding, so none of them shows it.
+ */
+
+import type {Meta, StoryObj} from '@storybook/react';
+import {useState, type ComponentProps, type ReactNode} from 'react';
+import {BottomSheet} from '@astryxdesign/core/BottomSheet';
+import {Button} from '@astryxdesign/core/Button';
+
+const meta = {
+ title: 'A11y/BottomSheet',
+ tags: ['no-visual'],
+} satisfies Meta;
+
+export default meta;
+type Story = StoryObj<typeof meta>;
+
+const SENTENCE =
+ 'The sheet scrolls its content once it reaches its height, and the last line still clears the bottom edge by the content padding.';
+
+function DirectContentSheet({
+ height,
+ children,
+}: {
+ height: ComponentProps<typeof BottomSheet>['height'];
+ children: ReactNode;
+}) {
+ const [isOpen, setIsOpen] = useState(false);
+ return (
+ <>
+ <Button label="Open sheet" onClick={() => setIsOpen(true)} />
+ <BottomSheet
+ isOpen={isOpen}
+ onOpenChange={setIsOpen}
+ label="Direct content"
+ height={height}>
+ {children}
+ </BottomSheet>
+ </>
+ );
+}
+
+const longText = Array.from({length: 24}, () => SENTENCE).join(' ');
+
+const blocks = Array.from({length: 24}, (_, i) => (
+ <p key={i} style={{margin: 0}}>
+ Paragraph {i + 1}. {SENTENCE}
+ </p>
+));
+
+export const HugDirectText: Story = {
+ render: () => (
+ <DirectContentSheet height="hug">{longText}</DirectContentSheet>
+ ),
+};
+
+export const HugDirectBlocks: Story = {
+ render: () => <DirectContentSheet height="hug">{blocks}</DirectContentSheet>,
+};
diff --git a/docs/specs/components/BottomSheet/BottomSheet.spec.md b/docs/specs/components/BottomSheet/BottomSheet.spec.md
index d0e4da2156..9168decd4a 100644
--- a/docs/specs/components/BottomSheet/BottomSheet.spec.md
+++ b/docs/specs/components/BottomSheet/BottomSheet.spec.md
@@ -218,8 +218,9 @@ remain documented in `BottomSheet.doc.mjs`.
open-layer allowance of `spec:AST-017` FR60, DEC-29). An open sheet's frame
has these elements, each with one job:
- the dialog carries the sheet's dialog role, modality and the top layer
- when the sheet is modal, and holds the panel at the block end with its
- own grid; a covered sheet's recede (FR6) is this element's transform;
+ when the sheet is modal, and hosts the panel at the bottom edge, so a
+ percentage `height` is a share of the viewport; a covered sheet's recede
+ (FR6) is this element's transform;
- the panel paints the `bottom-sheet` target;
- the grabber bar is the drag handle, and its `::before` draws the handle;
- the body is the scroll area;
diff --git a/packages/core/src/BottomSheet/BottomSheet.tsx b/packages/core/src/BottomSheet/BottomSheet.tsx
index ef271dc140..9fcab3a3f8 100644
--- a/packages/core/src/BottomSheet/BottomSheet.tsx
+++ b/packages/core/src/BottomSheet/BottomSheet.tsx
@@ -147,12 +147,17 @@ const styles = stylex.create({
},
// An open standalone dialog positions its panel: the panel sits at its
// block end, centred, with no wrapper. A tap beside a narrower panel lands
- // on the dialog, which light dismiss reads. The stack's recede applies to
- // this dialog too, so a covered sheet shrinks and lifts as one.
+ // on the dialog, which light dismiss reads. A flex row, not a grid: WebKit
+ // lays a grid host out again on each render inside the sheet, which makes
+ // each update slower. Not a column: WebKit then drops the content's
+ // block-end padding from the scroll range. In a row the panel's height is
+ // its own cross size, so a sheet taller than the viewport runs past the top
+ // edge, as in a grid. The stack's recede applies to this dialog too, so a
+ // covered sheet shrinks and lifts as one.
dialogPanelHost: {
- display: 'grid',
- alignContent: 'end',
- justifyItems: 'center',
+ display: 'flex',
+ justifyContent: 'center',
+ alignItems: 'flex-end',
},
// A non-modal sheet is in the top layer as a manual popover, so it has no
// page z-index (AST-027). Below the Popover API floor, `show()` leaves it
diff --git a/packages/core/src/BottomSheet/__tests__/BottomSheetScrollEnd.a11y.browser.spec.ts b/packages/core/src/BottomSheet/__tests__/BottomSheetScrollEnd.a11y.browser.spec.ts
new file mode 100644
index 0000000000..0db3ec2cad
--- /dev/null
+++ b/packages/core/src/BottomSheet/__tests__/BottomSheetScrollEnd.a11y.browser.spec.ts
@@ -0,0 +1,87 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file BottomSheetScrollEnd.a11y.browser.spec.ts
+ * @input The `A11y/BottomSheet` direct-content stories in a built Storybook,
+ * in Chromium and WebKit.
+ * @output Browser evidence that a hug-height sheet whose overflowing content
+ * sits directly in its content box keeps that box's block-end padding in the
+ * scroll range: at the scroll end the last line, or the last block, clears
+ * the end of the range by at least the padding.
+ * @position Guards the open dialog's panel host (BottomSheet.tsx): a flex
+ * column host gave WebKit's content box a definite height, so the content
+ * overflowed the box and the padding fell out of the scroll range. WebKit
+ * here is desktop WebKit under Playwright, not iOS Safari.
+ */
+
+import {expect, test} from '@playwright/test';
+import {
+ DEFAULT_STORYBOOK_DIR,
+ serveStorybook,
+ type StaticServer,
+} from '@astryxdesign/a11y-spec/storybook';
+
+let storybook: StaticServer;
+test.beforeAll(async () => {
+ storybook = await serveStorybook(
+ process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR,
+ );
+});
+test.afterAll(async () => {
+ await storybook?.close();
+});
+
+test.use({viewport: {width: 390, height: 844}, hasTouch: true});
+
+for (const story of ['hug-direct-text', 'hug-direct-blocks']) {
+ test(`${story}: the content box's block-end padding stays in the scroll range`, async ({
+ page,
+ }) => {
+ await page.goto(
+ `${storybook.origin}/iframe.html?id=a11y-bottomsheet--${story}&viewMode=story`,
+ );
+ await page.getByRole('button', {name: 'Open sheet', exact: true}).click();
+ const viewport = page.getByRole('group', {
+ name: 'Direct content',
+ exact: true,
+ });
+ await expect(viewport).toHaveAttribute('data-scrollable-block', 'true');
+ // The entrance has settled: nothing on the page is still running.
+ await expect
+ .poll(async () =>
+ page.evaluate(
+ () =>
+ document
+ .getAnimations()
+ .filter(animation => animation.playState === 'running').length,
+ ),
+ )
+ .toBe(0);
+ const {clearance, padding} = await viewport.evaluate(element => {
+ element.scrollTop = element.scrollHeight;
+ const content = element.querySelector<HTMLElement>(
+ '[data-scroll-content]',
+ );
+ if (content == null) {
+ throw new Error('no content box');
+ }
+ const range = document.createRange();
+ range.selectNodeContents(content);
+ const last = Math.max(
+ ...[...range.getClientRects()].map(rect => rect.bottom),
+ );
+ // The last content's end, in the scroll range's own coordinates.
+ const end =
+ last -
+ element.getBoundingClientRect().top -
+ element.clientTop +
+ element.scrollTop;
+ return {
+ clearance: element.scrollHeight - end,
+ padding: Number.parseFloat(getComputedStyle(content).paddingBlockEnd),
+ };
+ });
+ expect(padding).toBeGreaterThan(0);
+ expect(clearance).toBeGreaterThanOrEqual(padding - 0.5);
+ });
+}