Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/bottom-sheet-drag-restyle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/core': patch
---

[fix] BottomSheet: a move of a touch drag no longer restyles the sheet's content. Each move writes the scrim's opacity on the dialog as a custom property, and the property inherited into the sheet, so the browser restyled every element in the sheet on every move: 51 elements a move in a Tall sheet with a short list, 84 in PowerSearch's Filters sheet with three filters, and more with more content. The sheet's panel now ends that inheritance, and a move restyles the dialog, its backdrop, the panel and the edge tint. The scrim follows the drag as before. This applies to the sheet that owns the scrim: a single BottomSheet, or the first sheet of a stack, such as PowerSearch's Filters sheet and Tokenizer's sheet.

@imdreamrunner
25 changes: 25 additions & 0 deletions packages/core/src/BottomSheet/BottomSheet.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4927,6 +4927,31 @@ describe('BottomSheet', () => {
});
});

describe('scrim property isolation', () => {
// A drag writes the scrim's opacity on the dialog for each move, and only
// the dialog's backdrop reads it. An inherited custom property restyles
// every element under the one it changes on. jsdom reports the declared
// `initial`. A browser computes no value, which the interaction proof
// BottomSheetDragRestyle covers.
it("declares the dialog's scrim properties `initial` on the sheet panel", () => {
render(
<BottomSheet isOpen onOpenChange={() => {}} label="Filters">
Content
</BottomSheet>,
);
const dialog = screen.getByRole('dialog', {hidden: true});
dialog.style.setProperty('--_sheet-scrim-opacity', '0.5');
dialog.style.setProperty('--_sheet-scrim-duration', '120ms');
const computed = window.getComputedStyle(getSheet());
expect(computed.getPropertyValue('--_sheet-scrim-opacity')).toBe(
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved
'initial',
);
expect(computed.getPropertyValue('--_sheet-scrim-duration')).toBe(
'initial',
);
});
});

describe('container padding isolation', () => {
it('resets container padding custom properties to 0px on the sheet panel element', () => {
render(
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/BottomSheet/BottomSheetPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,12 @@ const styles = stylex.create({
},
transitionTimingFunction: easeVars['--ease-standard'],
willChange: 'transform, opacity',
// The dialog writes its scrim's opacity on itself for each move of a drag,
// and only its backdrop reads it. A custom property inherits, so each
// write would restyle every element in the sheet. The panel ends the
// inheritance, so the restyle stops here.
'--_sheet-scrim-opacity': 'initial',
'--_sheet-scrim-duration': 'initial',
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved
},
// A sheet present on page load opens where it rests (spec:AST-013 FR13):
// the collapse reduced motion uses, so the transition still ends.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

/**
* @file BottomSheetDragRestyle.interaction.browser.spec.ts
* @input The built "Tall sheet" BottomSheet story, real touch input (Chromium
* CDP) and the interaction harness's rendering trace
* @output A proof of the style work a touch drag does. A move restyles the
* dialog and the panel, never the sheet's content.
* @position An interaction proof beside
* BottomSheetDetent.interaction.browser.spec.ts, on the same harness.
*/

import {
expect,
test,
type Locator,
type Page,
} from '@astryxdesign/a11y-spec/playwright';
import {
drag,
openStory,
touchDriver,
traceRendering,
waitForRest,
withStorybook,
type TouchDriver,
} from '@astryxdesign/interaction-harness';

const storybook = withStorybook(test);

// The most elements one style recalculation may restyle between two moves.
// A move restyles the dialog, its backdrop, the panel and the edge tint. The
// limit leaves room for an engine's own boxes. A restyle of the sheet's
// content counts every element in it.
const RESTYLED_PER_MOVE = 6;

interface OpenSheet {
driver: TouchDriver;
sheet: Locator;
handle: {x: number; y: number};
}

async function openSheet(page: Page): Promise<OpenSheet> {
await openStory(page, storybook(), 'core-bottomsheet--tall-sheet');
const driver = await touchDriver(page);
const trigger = page.getByRole('button', {name: 'Open nearby places'});
const box = await trigger.boundingBox();
if (box == null) {
throw new Error('no trigger');
}
await driver.tap({x: box.x + box.width / 2, y: box.y + box.height / 2});
const sheet = page
.getByRole('dialog', {name: 'Nearby places'})
.locator('.astryx-bottom-sheet')
.first();
await expect(sheet).toBeVisible();
await waitForRest(sheet);
const rect = await sheet.boundingBox();
if (rect == null) {
throw new Error('no sheet');
}
return {
driver,
sheet,
handle: {x: rect.x + rect.width / 2, y: rect.y + 12},
};
}

test("a move of a drag restyles the dialog and the panel, not the sheet's content", async ({
page,
browserName,
}) => {
test.skip(browserName !== 'chromium', 'rendering traces are Chromium-only');
const {driver, sheet, handle} = await openSheet(page);
// The proof needs content that a restyle of the whole sheet would count.
const contentElements = await sheet.evaluate(
element => element.querySelectorAll('*').length,
);
expect(contentElements).toBeGreaterThan(4 * RESTYLED_PER_MOVE);
let steady = {from: 0, to: 0};
const trace = await traceRendering(page, async () => {
const played = await driver.play(
drag(
handle,
{x: handle.x, y: handle.y + 240},
{durationMs: 600, hz: 60, restMs: 150},
),
);
const moves = played.filter(event => event.type === 'touchMove');
// The steady part of the drag: its first moves commit the drag's start,
// and the lift commits its release.
steady = {
from: moves[4].returnedAt,
to: moves[moves.length - 1].dispatchedAt,
};
await waitForRest(sheet);
});
const restyled = trace.events
.filter(
event =>
event.name === 'UpdateLayoutTree' &&
event.t >= steady.from &&
event.t <= steady.to,
)
.map(event => event.elements ?? 0);
// The drag wrote the scrim: a move's recalculation restyles the dialog too.
expect(Math.max(...restyled), JSON.stringify(restyled)).toBeGreaterThan(1);
expect(Math.max(...restyled), JSON.stringify(restyled)).toBeLessThanOrEqual(
RESTYLED_PER_MOVE,
);
});
5 changes: 5 additions & 0 deletions packages/core/src/theme/derivedVarRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ const STRUCTURAL_VARS = new Set([
// Also beside it: how far above the viewport's bottom a layer ends while the
// keyboard is up. Runtime geometry, never authored by a theme.
'--_layer-keyboard-inset-block-end',
// A sheet's scrim opacity and fade time. The sheet writes both on its
// dialog for the backdrop, and its panel resets them so the content does
// not inherit them. Runtime state, never authored by a theme.
'--_sheet-scrim-opacity',
'--_sheet-scrim-duration',
]);

/**
Expand Down
Loading