Skip to content

feat(Sticky): add a reusable sticky wrapper - #11866

Open
aashish254 wants to merge 3 commits into
meta:mainfrom
aashish254:add-sticky-component
Open

aashish254 wants to merge 3 commits into
meta:mainfrom
aashish254:add-sticky-component

Conversation

@aashish254

@aashish254 aashish254 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

User need

Issue #2613 identifies a recurring layout need: keep a panel or heading in view while its scroll container moves. Today, builders write position: sticky styles for each case. That repeats layout code and makes each example responsible for choosing the right scroll boundary and offsets. A reusable wrapper gives callers one typed way to express the behavior and gives the CLI a working example.

Problem and solution fit

This adds one Sticky wrapper. It applies CSS sticky positioning to its children, supports vertical, horizontal, or both axes, and accepts edge offsets. It does not change the existing layout primitives.

Before:

const styles = stylex.create({panel: {position: 'sticky', top: 16}});
<XDSVStack xstyle={styles.panel}>...</XDSVStack>

After:

<Sticky offsetTop={16}>
  <XDSVStack>...</XDSVStack>
</Sticky>

Current specification

There is no current Sticky component or module record at the merge base. The repository's public component API contract routes an undeclared public API and behavior to an owner decision. This PR leaves specification authorship with maintainers. The component surface and whether a standalone wrapper is the right API remain pending owner review, so this PR is not ready to merge yet.

Public delta and caller burden

  • Exports Sticky, StickyProps, and StickyAxis from @astryxdesign/core and @astryxdesign/core/Sticky.
  • axis defaults to 'vertical'; it may be 'horizontal' or 'both'.
  • offsetTop defaults to 0. Optional offsetBottom, offsetInlineStart, and offsetInlineEnd set other active edges. Inline offsets follow writing direction.
  • isEnabled defaults to true and disables sticky positioning when false.
  • className, style, xstyle, ref, and supported HTML attributes pass to the root div.
  • The component adds no ARIA behavior or theme target. Callers choose the semantic element and can pass their own StyleX styles through xstyle.
  • The unmerged branch's offsetLeft and offsetRight names were corrected to logical offsetInlineStart and offsetInlineEnd before release; no published API changes.

Design and alternatives

The wrapper keeps sticky positioning local to one element and lets the browser use its nearest scroll container. Builders can still style the wrapper with xstyle or compose it with an existing layout component. Issue #2613 also suggests adding sticky props to layout primitives; the owner must decide whether this wrapper is the right public surface.

Evidence

  • Focused tests cover both axes, all four offsets, disabled behavior, forwarded event props, and xstyle.
  • Component docs and Storybook stories show default and offset behavior.
  • A CLI block demonstrates a sticky heading inside a scrollable task list.
  • Component and template documentation pass their authoring parsers.

Scope

Components: Sticky

  • One capability is added.
  • Supporting docs, focused tests, package exports, and a CLI example ship with it.
  • Unrelated fixes and policy changes were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

  • vitest run packages/core/src/Sticky/__tests__/Sticky.test.tsx — 12 passed.
  • Focused ESLint — passed.
  • tsc --noEmit --pretty false --project packages/core/tsconfig.build.json — passed.
  • git diff --check — passed.
  • node scripts/pre-review.mjs --base upstream/main — zero automated findings; the public API owner decision remains open.
  • The broader CLI test setup could not start: its global setup invokes pnpm -F @astryxdesign/core build, and Corepack's registry fetch failed in this environment. The Sticky component doc and CLI TemplateDoc were validated directly with their authoring parsers.

- New Sticky component with axis control (vertical/horizontal/both)
- Offset controls (offsetTop, offsetRight, offsetBottom, offsetLeft)
- isEnabled prop (default true) to toggle sticky behavior
- StyleX theming via themeProps('sticky', {axis, offsets, isEnabled})
- Reduced motion awareness (prefers-reduced-motion)
- Full TypeScript types extending BaseProps<HTMLDivElement>
- 12 test cases in __tests__/Sticky.test.tsx

Closes: meta#2613
@vercel

vercel Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Error Error Nov 18, 2026 5:15pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
❓ Needs maintainer input (for maintainers only) Nov 18, 2026, 5:38 PM UTC

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 15, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge needs:design-review Affects visuals — Design should review labels Nov 15, 2026
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · df57c0c

⏳ Building… Until it's ready, Storybook · Sandbox open the branch's previous preview.

Current run: The current CI run concluded failure. Current analysis is unavailable.


Generated by PR Enrichment workflow | View current CI run

@aashish254 aashish254 changed the title feat: add Sticky component with StyleX theming support feat(Sticky): add a reusable sticky wrapper Nov 18, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting on an engineering owner: no spec defines a standalone Sticky component yet, and the pull request also has defects to fix.

  • The new component and block are missing from the generated route files, so node apps/docsite/scripts/generate-data.mjs fails on the ShadCN route lock and apps/sandbox/src/route-manifest.test.ts fails; regenerate internal/shadcn-registry/routes.lock.json with UPDATE_SHADCN_ROUTE_LOCK=1 and add /templates/StickyScrollPanel/ to apps/sandbox/scripts/next-export-routes.json.
  • offsetBottom and offsetInlineEnd cannot be used alone, because the axis styles always set top: 0 and inset-inline-start: 0 and offsetTop defaults to 0 (Sticky.tsx lines 29-38 and 138), so a bottom bar also pins to the top.
  • Native position: sticky binds to the nearest CSS scroll container, so a horizontal Sticky inside a block-only ScrollableArea scrolls away instead of using the nearest inline scroll owner, which the scrollable-container spec (AST-025 FR10 and FR11) requires.
  • axis: 'vertical' | 'horizontal' and the four offset* props are new words for existing concepts; the system uses the logical 'block' | 'inline' | 'both' (as on ScrollableArea) and inset with logical edges (as on LayerProvider).
  • With isEnabled={false}, the inline position: static (Sticky.tsx line 179) replaces a caller's style.position; leave styles.sticky out instead of overriding.
  • The changeset calls the addition a fix ("Fix sticky offsets and forward consumer StyleX styles"), but Sticky is new, so please describe it as an addition.
  • The StickyScrollPanel example's list overflows its 280px viewport by about 6px, so it shows almost no sticky behaviour; lower its height or add rows.

Approval also needs an engineering owner to provide or identify the spec that governs a standalone Sticky: whether Core ships it at all (rather than sticky props on layout primitives, as #2613 proposes) and which record defines its props, defaults and scroll-owner resolution. An engineering owner records that decision by commenting /approve-spec <full head SHA> on this pull request, and the author may do so only if they are an engineering owner.

Claims and files checked

Review mode: full; reason: author-not-engowner

  • Changeset "fixes sticky offsets and forwards StyleX styles": false; the base has no Sticky, so this adds one.
  • Exports Sticky, StickyProps and StickyAxis from the root and @astryxdesign/core/Sticky: verified (index.ts, package.json, core build).
  • axis defaults to vertical and accepts horizontal or both: verified (Sticky.tsx line 137).
  • offsetTop defaults to 0 and the other offsets set other active edges: partly false; the start edge stays active (browser check), though inline offsets do follow writing direction.
  • isEnabled defaults to true and turns sticky off: verified, but it also overrides style.position.
  • className, style, xstyle, ref and HTML attributes reach the root: verified by code and tests, except style.position while disabled.
  • No ARIA behaviour or theme target is added: verified.
  • The left and right names were corrected to logical inline names: verified.
  • Tests cover the axes, offsets, disabled state, events and xstyle: verified; 12 pass.
  • Docs and stories show default and offset behaviour: verified; the header pins at 17px and 41px after scrolling.
  • The CLI block shows a sticky heading over a scrolling list: partly; the list scrolls about 6px.
  • Doc parsers, focused ESLint, tsc and git diff --check pass: verified.
  • The pre-review script reports no automated findings: not run in this review.
  • Public text carries no internal context: verified.
  • .changeset/sticky-component.md: wording is false (above).
  • apps/storybook/stories/Sticky.stories.tsx: clear.
  • packages/cli/assets/templates/blocks/components/Sticky/StickyScrollPanel.tsx: barely scrolls; its route entries are missing.
  • packages/cli/assets/templates/blocks/components/Sticky/StickyScrollPanel.doc.mjs: clear.
  • packages/core/package.json: clear; the subpath waits on the owner decision.
  • packages/core/src/Sticky/Sticky.doc.mjs: describes the offsets as independent edges, which they are not.
  • packages/core/src/Sticky/Sticky.tsx: findings above.
  • packages/core/src/Sticky/__tests__/Sticky.test.tsx: clear; the class-name checks do not show which edges are active.
  • packages/core/src/Sticky/index.ts: clear.
  • packages/core/src/index.ts: clear; the root export waits on the owner decision.

Automated review (maintainer link)

Comment on lines +29 to +38
axisVertical: {
top: 0,
},
axisHorizontal: {
insetInlineStart: 0,
},
axisBoth: {
top: 0,
insetInlineStart: 0,
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These axis styles always set top: 0 and inset-inline-start: 0, and offsetTop defaults to 0 (line 138). So <Sticky offsetBottom={0}> also pins to the top: in Chromium it sits 1px from the top after you scroll past it, where position: sticky; bottom: 0 leaves the view. offsetInlineEnd alone pins to the inline start the same way. Set only the edges the caller gives, and fall back to the start edge only when no edge on that axis is set.

// Types
// =============================================================================

export type StickyAxis = 'both' | 'horizontal' | 'vertical';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'vertical' | 'horizontal' is a new word for the logical 'block' | 'inline' | 'both' that ScrollableArea's axis already takes, and the offset* props below name what the system calls inset, as LayerProvider's inset={{blockStart, blockEnd, inlineStart, inlineEnd}} does (public-component-api INV2, DEC-1).

// Merge with any additional props
const finalStyle: React.CSSProperties = {
...style,
...(isEnabled ? {} : {position: 'static'}), // override to static when disabled

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This inline position: 'static' replaces a caller's style={{position: 'relative'}}, so an absolutely positioned child loses its anchor. Leave styles.sticky out of stylex.props when isEnabled is false and drop this override.

'@astryxdesign/cli': minor
---

Fix sticky offsets and forward consumer StyleX styles.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The base has no Sticky, so this release note announces a fix that is not one. Suggested: "Add Sticky, a wrapper that keeps its content at an edge of its nearest scroll container, and a CLI example block."

<Card width={360} padding={3}>
<ScrollableArea
axis="block"
height={280}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The five rows overflow this 280px viewport by about 6px (scrollHeight 286 in Chromium), so the heading has almost nothing to stay above, and with other font metrics the list can fit and not scroll at all. A lower height, such as 200, or more rows makes the example show the behaviour.

This branch had an error being deployed

1 failed deployment
Preview — df57c0cd Deployed Nov 18, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant