Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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-clears-grab-bar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/core': patch
---

[feat] BottomSheet: at rest, a sheet's content starts below the grab bar whatever its `padding`, so the first line is no longer drawn through the bar's fade. The block-start inset is never less than the bar's height (`--spacing-6`): the band under the bar is not padding a child escapes, so a lone `Section` starts below the bar too; scrolled content still passes beneath it. A sheet at the default padding starts its content 8 px lower, and one with `padding={0}` starts it below the bar. Core's own `padding={0}` sheets (the touch date and time pickers, DropdownMenu and ContextMenu sheets) no longer reserve that band themselves, so the pickers look the same and a menu's first row sits 8 px lower.
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved

@vjeux
3 changes: 2 additions & 1 deletion apps/storybook/stories/BottomSheet.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ export const TextOnlyFitting: Story = {
* Content placed directly in a sheet. The sheet pads it like Dialog, by
* default or at the `padding` step given here, and a full-bleed Divider
* reaches the sheet's edges because the content box publishes its inset.
* `padding={0}` restores the unpadded content box.
* `padding={0}` removes the padding; the content still starts below the grab
* bar's band.
*/
export const ContainerPadding: Story = {
args: {
Expand Down
7 changes: 6 additions & 1 deletion docs/architecture/container-padding.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ pads caller content and publishes the applied inset. The inset resolves from the
`padding` prop on the public spacing scale, then the theme's `padding` properties
on the `bottom-sheet` component, then `--spacing-4` on every logical edge,
matching Dialog. This prop and theme property are BottomSheet's projection of
container lowering.
container lowering. At the block start a sheet keeps a band under its floating
grab bar (`--spacing-6`) that is not container padding: it publishes only the
padding past that band and applies the band on top, so its applied block-start
inset is `max(padding, --spacing-6)` and a lone Section or Layout that escapes
the published padding still starts below the bar (`component:BottomSheet`,
Content area inset).
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved

Edge compensation is a two-sided geometry contract, not a token contract:

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/BottomSheet/BottomSheet.doc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const docs = {
derived: [{property: 'padding', expand: 'container'}],
},
description:
"A mobile touch sheet that rises from the bottom edge, with animated entrance and exit, a grab handle, optional drag-to-resize snap points, and purpose-controlled dismissal. Like Dialog, it is a padded container: content starts at the theme's bottom-sheet padding (--spacing-4 by default), and a lone Section child or bleed children such as Table and Divider align against it. A sheet always owns a native <dialog>; inside BottomSheetSwitcher the switcher presents and closes that dialog as the flow moves between steps. In both modes, ref and shared DOM props target the visual panel <div>.",
"A mobile touch sheet that rises from the bottom edge, with animated entrance and exit, a grab handle, optional drag-to-resize snap points, and purpose-controlled dismissal. Like Dialog, it is a padded container: content starts at the theme's bottom-sheet padding (--spacing-4 by default), and a lone Section child or bleed children such as Table and Divider align against it. At the top the content always starts below the grab bar's 24px band, which is not padding a child escapes, so the first row never sits under the bar; scrolled content passes beneath it. A sheet always owns a native <dialog>; inside BottomSheetSwitcher the switcher presents and closes that dialog as the flow moves between steps. In both modes, ref and shared DOM props target the visual panel <div>.",
props: [
{
name: 'isOpen',
Expand Down Expand Up @@ -146,7 +146,7 @@ export const docs = {
name: 'padding',
type: '0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10',
description:
'Internal padding of the sheet content using the spacing scale, matching Dialog. When omitted, uses the theme default for bottom sheets (--spacing-4 unless the theme sets padding on bottom-sheet). A lone Section child escapes the padding, and bleed children such as Table and Divider compensate against it. Use 0 for edge-to-edge content that supplies its own inset.',
"Internal padding of the sheet content using the spacing scale, matching Dialog. When omitted, uses the theme default for bottom sheets (--spacing-4 unless the theme sets padding on bottom-sheet). A lone Section child escapes the padding, and bleed children such as Table and Divider compensate against it. Use 0 for edge-to-edge content that supplies its own inset. Whatever the padding, the block-start inset is never less than the grab bar's height (--spacing-6), so resting content starts below the bar.",
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved
},
{
name: 'height',
Expand Down
19 changes: 15 additions & 4 deletions packages/core/src/BottomSheet/BottomSheet.spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,13 @@ gap note.

## Compatibility and migration

- Released default preserved: `yes`; with no `padding` prop and no theme
padding, the Content area insets by `--spacing-4` on every logical edge, and
`padding={0}` keeps an unpadded Content area
- Released default preserved: `yes`, except the block-start inset; with no
`padding` prop and no theme padding, the Content area insets by
`--spacing-4` on the other logical edges, and `padding={0}` keeps them
unpadded. The block-start inset is never less than the grab bar's height
(`--spacing-6`), so a default sheet's content starts 8px lower, a
`padding={0}` sheet's and a lone Section's start below the bar
(`spec:AST-017/FR7`, a visible layout change, tagged `[feat]`)
- Compatibility class: no public prop, type, default, or export changes.
Stacking, the replace handoff, and non-modal top-layer hosting are behavior
of the existing component, tagged `[feat]` (`spec:AST-017/FR7`: a compatible
Expand Down Expand Up @@ -195,7 +199,14 @@ remain documented in `BottomSheet.doc.mjs`.
### Transformation and precedence order

- Content area inset: the `padding` prop, then the theme's `padding` properties
on `bottom-sheet`, then `--spacing-4` on every logical edge.
on `bottom-sheet`, then `--spacing-4` on every logical edge. At rest the
block-start inset is never less than the grab bar's height (`--spacing-6`),
so the first row starts below the bar; scrolled content still passes under it.
That band under the bar is not container padding: the Content area publishes
only the block-start padding past it (`max(padding - --spacing-6, 0)`) and
applies the band on top, so a lone Section or a Layout that escapes its
padding still starts below the bar. Every other edge applies and publishes
the same inset.
- Stack order: open order, then tree order for sheets opening in one update
(FR5). A sheet that closes and reopens takes a new place on top.
- Native top-layer order is derived from the stack order, not trusted: where
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/BottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ interface BottomSheetSharedProps extends BaseProps<HTMLDivElement> {
* unless the theme sets `padding` on `bottom-sheet`), matching Dialog. The
* content box is a container: a Section that is its only child escapes the
* padding, and bleed children such as Table and Divider compensate against
* it. Pass `0` for content that supplies its own inset.
* it. Pass `0` for content that supplies its own inset. Whatever the padding,
* the block-start inset is never less than the grab bar's height
* (`--spacing-6`), so resting content starts below the bar.
*/
padding?: SpacingStep;

Expand Down
35 changes: 32 additions & 3 deletions packages/core/src/BottomSheet/BottomSheetPanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,9 @@ describe('BottomSheetPanel', () => {
['block-start', 'padding-top'],
['block-end', 'padding-bottom'],
] as const;
// The block-start inset never drops below the grab bar's height, so
// resting content starts below the bar (component:BottomSheet, Content
// area inset); it is applied and published alike.
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved
Comment thread
astracat-bot[bot] marked this conversation as resolved.
Resolved

function renderWithPadding(padding?: 0 | 2) {
render(
Expand All @@ -432,6 +435,13 @@ describe('BottomSheetPanel', () => {
return getComputedStyle(screen.getByTestId('sheet-child').parentElement!);
}

// The band under the grab bar is applied on top of the published
// block-start, which is only the padding past the band: a lone Section
// escapes that and still starts below the bar (component:BottomSheet,
// Content area inset).
const BAND =
'calc(var(--container-padding-block-start,0px)+var(--spacing-6))';

it("pads by Dialog's default chain and publishes the inset it applies", () => {
const computed = renderWithPadding();
for (const [edge, property] of EDGES) {
Expand All @@ -444,6 +454,16 @@ describe('BottomSheetPanel', () => {
expect(published, edge).toContain(
'var(--astryx-bottom-sheet-padding,var(--spacing-4))',
);
if (edge === 'block-start') {
expect(published, edge).toMatch(
/^max\(calc\(.*-var\(--spacing-6\)\),0px\)$/,
);
expect(
computed.getPropertyValue(property).replace(/\s+/g, ''),
edge,
).toBe(BAND);
continue;
}
// Applied padding reads the published value, so bleed children
// subtract exactly the inset they sit in.
expect(computed.getPropertyValue(property), edge).toBe(
Expand All @@ -469,11 +489,20 @@ describe('BottomSheetPanel', () => {
const computed = renderWithPadding(padding);
const expected = `var(--spacing-${padding})`;
for (const [edge, property] of EDGES) {
const published =
edge === 'block-start'
? `max(calc(${expected} - var(--spacing-6)), 0px)`
: expected;
expect(
computed
.getPropertyValue(`--container-padding-${edge}`)
.replace(/\s+/g, ''),
edge,
).toBe(published.replace(/\s+/g, ''));
expect(
computed.getPropertyValue(`--container-padding-${edge}`),
computed.getPropertyValue(property).replace(/\s+/g, ''),
edge,
).toBe(expected);
expect(computed.getPropertyValue(property), edge).toBe(expected);
).toBe(edge === 'block-start' ? BAND : expected.replace(/\s+/g, ''));
}
expect(computed.getPropertyValue('--layout-padding-inner-x')).toBe(
expected,
Expand Down
71 changes: 59 additions & 12 deletions packages/core/src/BottomSheet/BottomSheetPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import {container} from '../Layout/container.stylex';
import type {SpacingToken} from '../Layout/container.stylex';
import {
containerPaddingBlockEndVarStyles,
containerPaddingBlockStartVarStyles,
containerPaddingInlineVarStyles,
overlayPaddingReset,
paddingStyles,
Expand Down Expand Up @@ -84,10 +83,10 @@ export type {BottomSheetSnapPoint};
const OVERSCROLL_PADDING = 48;
const MOBILE_KEYBOARD_BOTTOM_CLEARANCE = 48;
const TRANSITION_BACKSTOP_BUFFER_MS = 50;
// The floating handle bar's height. The bar is out of flow, so this is not
// layout space the content pays for -- the pill (4px, centered) lands 10-14px
// from the sheet's top edge, inside the space a content wrapper's own top
// padding already provides.
// The floating handle bar's height. The bar is out of flow; at rest the
// content box keeps a band this tall under it (`clearsGrabBar`), so the pill
// (4px, centered, 10-14px from the sheet's top edge) never sits on the first
// row, and scrolled content rides up beneath it.
const HANDLE_BAR_HEIGHT = spacingVars['--spacing-6'];

// Measure the same viewport the height budgets are written against. Those are
Expand Down Expand Up @@ -118,6 +117,49 @@ function snapPointsKeyFor(
return key;
}

// At rest the content starts below the floating grab bar whatever the
// padding, so the first row never sits under the bar's fade
// (component:BottomSheet, Content area inset). The band under the bar is not
// container padding: an explicit padding publishes only what reaches past
// the band, which a lone Section escapes, and `clearsGrabBar` applies the band
// on top. It is the content box's own padding, so it scrolls away with the
// content, which then passes under the bar.
const pastGrabBarStyles = stylex.create({
0: {
'--container-padding-block-start': `max(calc(${spacingVars['--spacing-0']} - ${HANDLE_BAR_HEIGHT}), 0px)`,
},
0.5: {
'--container-padding-block-start': `max(calc(${spacingVars['--spacing-0-5']} - ${HANDLE_BAR_HEIGHT}), 0px)`,
},
1: {
'--container-padding-block-start': `max(calc(${spacingVars['--spacing-1']} - ${HANDLE_BAR_HEIGHT}), 0px)`,
},
1.5: {
'--container-padding-block-start': `max(calc(${spacingVars['--spacing-1-5']} - ${HANDLE_BAR_HEIGHT}), 0px)`,
},
2: {
'--container-padding-block-start': `max(calc(${spacingVars['--spacing-2']} - ${HANDLE_BAR_HEIGHT}), 0px)`,
},
3: {
'--container-padding-block-start': `max(calc(${spacingVars['--spacing-3']} - ${HANDLE_BAR_HEIGHT}), 0px)`,
},
4: {
'--container-padding-block-start': `max(calc(${spacingVars['--spacing-4']} - ${HANDLE_BAR_HEIGHT}), 0px)`,
},
5: {
'--container-padding-block-start': `max(calc(${spacingVars['--spacing-5']} - ${HANDLE_BAR_HEIGHT}), 0px)`,
},
6: {
'--container-padding-block-start': `max(calc(${spacingVars['--spacing-6']} - ${HANDLE_BAR_HEIGHT}), 0px)`,
},
8: {
'--container-padding-block-start': `max(calc(${spacingVars['--spacing-8']} - ${HANDLE_BAR_HEIGHT}), 0px)`,
},
10: {
'--container-padding-block-start': `max(calc(${spacingVars['--spacing-10']} - ${HANDLE_BAR_HEIGHT}), 0px)`,
},
});

const styles = stylex.create({
sheet: {
pointerEvents: 'auto',
Expand Down Expand Up @@ -247,12 +289,14 @@ const styles = stylex.create({
// 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
// space a content wrapper's own top padding already provides.
// No reserve for the handle bar here: it floats over the scrolling area,
// so scrolled content rides up under the pill. The content box keeps the
// resting content clear of the bar instead (`clearsGrabBar`).
paddingBlockEnd: 0,
},
clearsGrabBar: {
paddingBlockStart: `calc(var(--container-padding-block-start, 0px) + ${HANDLE_BAR_HEIGHT})`,
},
content: {
// Preserve the body's block formatting (including margin/float isolation)
// and its definite percentage-height basis. min-content lets this real
Expand Down Expand Up @@ -803,12 +847,15 @@ export function BottomSheetPanel({
!usesThemePadding &&
effectivePadding !== 4 &&
containerPaddingInlineVarStyles[effectivePadding],
!usesThemePadding &&
effectivePadding !== 4 &&
containerPaddingBlockStartVarStyles[effectivePadding],
// An explicit padding publishes what reaches past the grab
// bar's band, like the theme default (Layout/container.stylex.ts).
!usesThemePadding && pastGrabBarStyles[effectivePadding],
!usesThemePadding &&
effectivePadding !== 4 &&
containerPaddingBlockEndVarStyles[effectivePadding],
// The band under the grab bar, on top of the published
// padding past it: max(padding, the bar) in all.
styles.clearsGrabBar,
),
),
)}>
Expand Down
Loading
Loading