Skip to content

fix(AspectRatio): match Radix primitive structure for DOM parity#2027

Draft
maxffarrell wants to merge 1 commit intohuntabyte:mainfrom
maxffarrell:aspect-ratio-parity
Draft

fix(AspectRatio): match Radix primitive structure for DOM parity#2027
maxffarrell wants to merge 1 commit intohuntabyte:mainfrom
maxffarrell:aspect-ratio-parity

Conversation

@maxffarrell
Copy link
Copy Markdown
Contributor

Summary

  • Moves the wrapper styles (position: relative, width: 100%, padding-bottom) from hard-coded style: directives into rootState.props so that they are merged with user-provided props via mergeProps
  • The outer <div> now receives mergedProps — meaning class, style, ref, and all HTML attributes the user passes attach to the outer container, matching the Radix primitive exactly
  • The inner <div> is now a pure implementation detail with hard-coded style:position="absolute" style:inset="0" and no user-accessible props

Motivation

The @radix-ui/react-aspect-ratio source renders two divs:

// outer — receives all user props (className, style, ref, …)
<Primitive.div style={{ position: 'relative', width: '100%', paddingBottom: `${100 / ratio}%`, ...style }} {...props} ref={forwardedRef}>
  // inner — implementation detail only
  <Primitive.div style={{ position: 'absolute', top: 0, right: 0, bottom: 0, left: 0 }}>
    {children}
  </Primitive.div>
</Primitive.div>

Source: https://github.com/radix-ui/primitives/blob/main/packages/react/aspect-ratio/src/aspect-ratio.tsx

Before this change, bits-ui applied user props to the inner div and hard-coded the wrapper styles on the outer div with style: directives. This meant class="overflow-hidden rounded-xl" would clip the inner absolute-positioned box instead of the outer padded wrapper — a subtle but observable difference from the React primitive.

Test plan

  • <AspectRatio.Root ratio={16/9} class="overflow-hidden rounded-xl"> — border-radius and overflow clipping apply to the outer wrapper ✓
  • ref binds to the outer container element ✓
  • style passed by the user merges with (and can extend) the wrapper styles ✓
  • svelte-check passes with 0 errors ✓

🤖 Generated with Claude Code

Move wrapper styles (position: relative, width, padding-bottom) onto the
root props so user-provided class/style/ref attach to the outer container
div — matching the @radix-ui/react-aspect-ratio source exactly.

The inner div now has hardcoded `position: absolute; inset: 0` via
style: directives rather than being user-accessible, matching Radix's
inner Primitive.div which only ever carries the absolute-positioning
styles.

Sources:
- https://github.com/radix-ui/primitives/blob/main/packages/react/aspect-ratio/src/aspect-ratio.tsx

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 17, 2026

⚠️ No Changeset found

Latest commit: 4c4daeb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 17, 2026

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
bits-ui ✅ Ready (View Log) Visit Preview 4c4daeb

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