Skip to content

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

TypeScript

fix(BottomSheet): give the sheet one uniform edge against the scrim (#5305)

Xinzi Zhou66c3750b10b5
diff --git a/.changeset/bottom-sheet-scrim-edge-hairline.md b/.changeset/bottom-sheet-scrim-edge-hairline.md
new file mode 100644
index 0000000000..b04ab2b654
--- /dev/null
+++ b/.changeset/bottom-sheet-scrim-edge-hairline.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] BottomSheet: give the sheet one uniform edge against the scrim. Two things were wrong in dark mode. The sheet drew no edge of its own — surface and scrim sit a few RGB steps apart and the `--shadow-high` drop shadow is black on near-black, so the left and right edges were invisible (measured 1.16:1 boundary contrast in dark against 2.89:1 in light); it now carries a `--border-width` / `--color-border` hairline on its three scrim-facing edges, the same treatment MobileNav gives its scrim-facing edge. And under a theme that packs an inset ring into `--shadow-high` (every bundled theme adds one in dark mode) that ring was painted over by an opaque content wrapper such as `Section`, so it showed only in the gap below where the content ended and the side edges appeared to change width partway down; the scrolling body now paints the surface across the sheet's whole inner box, hiding the ring evenly.
+
+@imdreamrunner
diff --git a/packages/core/src/BottomSheet/BottomSheetPanel.test.tsx b/packages/core/src/BottomSheet/BottomSheetPanel.test.tsx
index 83643d542b..8d8c88bf83 100644
--- a/packages/core/src/BottomSheet/BottomSheetPanel.test.tsx
+++ b/packages/core/src/BottomSheet/BottomSheetPanel.test.tsx
@@ -278,4 +278,54 @@ describe('BottomSheetPanel', () => {
expect(handleBar![1]).toContain('linear-gradient(to bottom');
expect(handleBar![1]).toContain("colorVars['--color-background-surface']");
});
+
+ // In dark mode the surface fill and the scrim sit a few RGB steps apart and
+ // the drop shadow is black on near-black, so the fill alone leaves the
+ // sheet's left and right edges invisible against the scrim. A hairline on
+ // the scrim-facing edges is what draws them. Asserted on the style
+ // definition for the same reason as the test above.
+ it('draws a hairline on the three edges that face the scrim', async () => {
+ const fs = await import('fs');
+ const path = await import('path');
+ const source = fs.readFileSync(
+ path.resolve(__dirname, './BottomSheetPanel.tsx'),
+ 'utf-8',
+ );
+
+ const sheet = source.match(/\n {2}sheet: \{([\s\S]*?)\n {2}\},/);
+ expect(sheet).not.toBeNull();
+ for (const edge of [
+ 'borderBlockStart',
+ 'borderInlineStart',
+ 'borderInlineEnd',
+ ]) {
+ expect(sheet![1]).toContain(`${edge}Width: borderVars['--border-width']`);
+ expect(sheet![1]).toContain(`${edge}Style: 'solid'`);
+ expect(sheet![1]).toContain(`${edge}Color: colorVars['--color-border']`);
+ }
+ // The block-end edge sits below the viewport, under the overscroll
+ // padding, so it carries no hairline to draw.
+ expect(sheet![1]).not.toContain('borderBlockEndWidth');
+ });
+
+ // A theme that packs an inset ring into --shadow-high (the bundled themes all
+ // add one in dark mode) draws it just inside the sheet, where an opaque
+ // content wrapper such as Section paints over it -- so it showed only in the
+ // gap below the content and the side edges appeared to change width partway
+ // down. The scrolling body paints the surface across the whole inner box to
+ // hide the ring evenly.
+ it('paints the surface across the scrolling body so the edge stays uniform', async () => {
+ const fs = await import('fs');
+ const path = await import('path');
+ const source = fs.readFileSync(
+ path.resolve(__dirname, './BottomSheetPanel.tsx'),
+ 'utf-8',
+ );
+
+ const body = source.match(/\n {2}body: \{([\s\S]*?)\n {2}\},/);
+ expect(body).not.toBeNull();
+ expect(body![1]).toContain(
+ "backgroundColor: colorVars['--color-background-surface']",
+ );
+ });
});
diff --git a/packages/core/src/BottomSheet/BottomSheetPanel.tsx b/packages/core/src/BottomSheet/BottomSheetPanel.tsx
index 2133d752d2..a193e8f0b1 100644
--- a/packages/core/src/BottomSheet/BottomSheetPanel.tsx
+++ b/packages/core/src/BottomSheet/BottomSheetPanel.tsx
@@ -34,6 +34,7 @@ import * as stylex from '@stylexjs/stylex';
import type {BaseProps} from '../BaseProps';
import {useDevWarning} from '../hooks';
import {
+ borderVars,
colorVars,
durationVars,
easeVars,
@@ -112,6 +113,22 @@ const styles = stylex.create({
width: '100%',
maxWidth: 640,
backgroundColor: colorVars['--color-background-surface'],
+ // Hairline on the three edges that face the scrim. The surface fill alone
+ // separates sheet from scrim in light mode, but not in dark: there the two
+ // sit within a few RGB steps of each other and the drop shadow is black on
+ // near-black, so the sheet's left and right edges disappear. Same
+ // treatment MobileNav gives its scrim-facing edge. The block-end edge is
+ // deliberately left bare; it sits below the viewport, under the overscroll
+ // padding.
+ borderBlockStartWidth: borderVars['--border-width'],
+ borderBlockStartStyle: 'solid',
+ borderBlockStartColor: colorVars['--color-border'],
+ borderInlineStartWidth: borderVars['--border-width'],
+ borderInlineStartStyle: 'solid',
+ borderInlineStartColor: colorVars['--color-border'],
+ borderInlineEndWidth: borderVars['--border-width'],
+ borderInlineEndStyle: 'solid',
+ borderInlineEndColor: colorVars['--color-border'],
borderStartStartRadius: radiusVars['--radius-container'],
borderStartEndRadius: radiusVars['--radius-container'],
boxShadow: shadowVars['--shadow-high'],
@@ -175,6 +192,15 @@ const styles = stylex.create({
overflowY: 'auto',
overscrollBehavior: 'none',
touchAction: 'pan-y',
+ // The scrolling area paints the surface itself, covering the sheet's whole
+ // inner box. Without it the sheet's edge is not uniform: a theme that packs
+ // an inset ring into --shadow-high (the bundled themes all add one in dark
+ // mode) draws that ring just inside the sheet, where an opaque content
+ // wrapper such as Section paints over it -- so the ring shows only in the
+ // gap below where the content ends, and the sheet's side edges appear to
+ // change width partway down. Painting the surface here hides the ring
+ // evenly, leaving the border below as the sheet's one edge.
+ backgroundColor: colorVars['--color-background-surface'],
// No reserve for the handle bar: it floats, so the content starts at the
// sheet's top edge and rides up under the pill. The pill is 4px centered
// in a 24px band, so it occupies only 10-14px from the edge -- inside the