Repository navigation
feat(Sticky): add a reusable sticky wrapper - #11866
aashish254 wants to merge 3 commits into
Conversation
- 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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
# Conflicts: # packages/core/package.json
There was a problem hiding this comment.
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.mjsfails on the ShadCN route lock andapps/sandbox/src/route-manifest.test.tsfails; regenerateinternal/shadcn-registry/routes.lock.jsonwithUPDATE_SHADCN_ROUTE_LOCK=1and add/templates/StickyScrollPanel/toapps/sandbox/scripts/next-export-routes.json. offsetBottomandoffsetInlineEndcannot be used alone, because the axis styles always settop: 0andinset-inline-start: 0andoffsetTopdefaults to0(Sticky.tsxlines 29-38 and 138), so a bottom bar also pins to the top.- Native
position: stickybinds to the nearest CSS scroll container, so a horizontalStickyinside a block-onlyScrollableAreascrolls 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 fouroffset*props are new words for existing concepts; the system uses the logical'block' | 'inline' | 'both'(as onScrollableArea) andinsetwith logical edges (as onLayerProvider).- With
isEnabled={false}, the inlineposition: static(Sticky.tsxline 179) replaces a caller'sstyle.position; leavestyles.stickyout instead of overriding. - The changeset calls the addition a fix ("Fix sticky offsets and forward consumer StyleX styles"), but
Stickyis new, so please describe it as an addition. - The
StickyScrollPanelexample's list overflows its 280px viewport by about 6px, so it shows almost no sticky behaviour; lower itsheightor 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,StickyPropsandStickyAxisfrom the root and@astryxdesign/core/Sticky: verified (index.ts,package.json, core build). axisdefaults to vertical and accepts horizontal or both: verified (Sticky.tsxline 137).offsetTopdefaults 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.isEnableddefaults to true and turns sticky off: verified, but it also overridesstyle.position.className,style,xstyle,refand HTML attributes reach the root: verified by code and tests, exceptstyle.positionwhile 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,
tscandgit diff --checkpass: 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.
| axisVertical: { | ||
| top: 0, | ||
| }, | ||
| axisHorizontal: { | ||
| insetInlineStart: 0, | ||
| }, | ||
| axisBoth: { | ||
| top: 0, | ||
| insetInlineStart: 0, | ||
| }, |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
'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 |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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.
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: stickystyles 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
Stickywrapper. 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:
After:
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
Sticky,StickyProps, andStickyAxisfrom@astryxdesign/coreand@astryxdesign/core/Sticky.axisdefaults to'vertical'; it may be'horizontal'or'both'.offsetTopdefaults to0. OptionaloffsetBottom,offsetInlineStart, andoffsetInlineEndset other active edges. Inline offsets follow writing direction.isEnableddefaults totrueand disables sticky positioning when false.className,style,xstyle,ref, and supported HTML attributes pass to the rootdiv.xstyle.offsetLeftandoffsetRightnames were corrected to logicaloffsetInlineStartandoffsetInlineEndbefore 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
xstyleor 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
xstyle.Scope
Components: Sticky
Testing
vitest run packages/core/src/Sticky/__tests__/Sticky.test.tsx— 12 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.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.