Skip to content

Add positionAreaContainingBlock option#428

Draft
jpzwarte wants to merge 1 commit into
oddbird:mainfrom
jpzwarte:feat/411-position-area-containing-block-option
Draft

Add positionAreaContainingBlock option#428
jpzwarte wants to merge 1 commit into
oddbird:mainfrom
jpzwarte:feat/411-position-area-containing-block-option

Conversation

@jpzwarte

@jpzwarte jpzwarte commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a positionAreaContainingBlock polyfill option that controls whether a position-area target is wrapped with an element approximating the containing block that position-area natively creates. The wrapper is correct but can interfere with author CSS that depends on the target's position in the DOM tree (direct-child/sibling combinators, the original parent's flex/grid layout, etc.). This option makes that tradeoff configurable.

  • true (default): always wrap the target — matches the current behavior most closely.
  • false: never wrap; the polyfill computes and applies inset values directly on the target instead. Avoids the extra element, but styles that resolve against the containing block (percentage sizes, auto/percentage margins, percentage padding, or stretch/anchor-center self-alignment) won't match native behavior.
  • 'auto': wrap only targets whose styles resolve against the containing block (same heuristics as above); position all other targets directly.

Implementation notes

  • polyfill.ts: new public option on AnchorPositioningPolyfillOptions (+ normalized). In applyAnchorPositions, a position-area target positions via wrapper ?? target; unwrapped targets resolve alignment to physical inset values via the new resolveAxisInsetValues helper.
  • position-area.ts: new PositionAreaContainingBlock type; isContainingBlockDependentDeclaration heuristic + property lists; addPositionAreaDeclarationBlockStyles emits the wrapped/unwrapped/both declaration sets; new markPositionAreaTarget, activeTargetStyles, and POSITION_AREA_TARGET_ATTRIBUTE for the unwrapped path. Wrapper insets renamed --pa-value-*--pa-wrapper-* so a shared 'auto' selector's target insets don't collide.
  • parse.ts: collects containing-block-dependent selectors during the AST walk and computes needsWrapper per target in 'auto' mode.

Testing

  • tsc --noEmit: clean
  • eslint: clean
  • Unit suite: 210 passing (25 new — covering the heuristic, all three declaration-emission modes, markPositionAreaTarget, dataForPositionAreaTarget, activeTargetStyles)
  • npm run build: succeeds

⚠️ Browser-level e2e verification of false/'auto' rendering was not run and should be confirmed before merge. Porting the e2e tests for the new modes is a follow-up.

🤖 Generated with Claude Code

Add a `positionAreaContainingBlock` polyfill option that controls whether a
`position-area` target is wrapped with an element approximating the containing
block that `position-area` natively creates.

- `true` (default): always wrap; matches the current behavior most closely.
- `false`: never wrap; the polyfill computes and applies inset values directly
  on the target instead.
- `'auto'`: wrap only targets whose styles resolve against the containing block
  (percentage sizes, `auto`/percentage margins, percentage padding, or
  `stretch`/`anchor-center` self-alignment); other targets are positioned
  directly.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@netlify

netlify Bot commented Jul 1, 2026

Copy link
Copy Markdown

Deploy Preview for anchor-position-wpt canceled.

Name Link
🔨 Latest commit 24f4296
🔍 Latest deploy log https://app.netlify.com/projects/anchor-position-wpt/deploys/6a44dc781d01bb000893367f

@netlify

netlify Bot commented Jul 1, 2026

Copy link
Copy Markdown

Deploy Preview for anchor-polyfill ready!

Name Link
🔨 Latest commit 24f4296
🔍 Latest deploy log https://app.netlify.com/projects/anchor-polyfill/deploys/6a44dc78c9bab10008d3de52
😎 Deploy Preview https://deploy-preview-428--anchor-polyfill.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant