[Bug Fix] Avatar: AvatarImage's class wins over the root (match shadcn)

Merged
PI
3d ago
+35-8

Related issue

None opened. Found while moving an app to the vega Avatar: a buyer's logo shown in an avatar can't be uncropped.

Description

AvatarImage(class: "object-contain") was ignored: the logo kept object-fit: cover and a wide logo showed only its middle. The root Avatar carried *:[img]:size-full *:[img]:rounded-full *:[img]:object-cover, and that variant outranks the image's own class. shadcn has no such rule on the root: AvatarImage alone styles the image (cn-avatar-image, aspect-square size-full object-cover + rounded-full from vega), and its className wins. This PR scopes the root rule to a plain <img> child ([&>img:not([data-slot])]:size-full rounded-full object-cover), so AvatarImage, which carries data-slot, owns its look as in shadcn.

A plain <img> passed straight into Avatar is still sized, rounded and cropped, as #602 meant (the root doesn't clip): measured 32px, round, object-fit: cover. AvatarImage already has size-full rounded-full object-cover of its own, so nothing else changes on screen.

  • gem/test/ruby_ui/avatar_test.rb: new test_image_class_overrides_object_fit; test_plain_img_child_is_sized_and_rounded checks the scoped rule.
  • The audit fixture gets an eighth avatar, a 4:1 logo with object-contain, on both sides; the Avatar baseline moves to shadcn 968d8cb.
  • MCP registry rebuilt.

The audit's collect doesn't read object-fit (not in STYLE_PROPS), so that Look line was measured by hand with getComputedStyle on img[alt=@logo]: main cover, this PR contain, shadcn contain. The font line is the environment's font stack, the same on main. The main run used main plus this PR's fixture (local 9d797ea8); the PR run used f1864145, which only lacks the baseline bump.

shadcn audit · main
shadcn audit  ruby-ui/ruby_ui
  base eb120059  head 9d797ea8  shadcn 968d8cb9
⚠️ Environment  font: "Inter Variable", "system-ui", -apple-system, "system-ui", "Segoe UI", Roboto, "Helvetica Neue", Arial, "sans-serif" vs "Inter Variable", sans-serif (light)
⚠️ Environment  font: "Inter Variable", "system-ui", -apple-system, "system-ui", "Segoe UI", Roboto, "Helvetica Neue", Arial, "sans-serif" vs "Inter Variable", sans-serif (dark)
✅ Theme  neutral tokens match shadcn
Avatar  (ref: bases/base/ui/avatar.tsx + style-vega.css @ 968d8cb9)
  ⏸ Look       properties: font-family
               Avatar, AvatarImage, AvatarFallback, AvatarBadge, AvatarGroup, AvatarGroupCount — explained by environment diff: font
  ✅ ARIA       Avatar, AvatarImage, AvatarFallback, AvatarBadge, AvatarGroup, AvatarGroupCount: accessibility tree matches
               ↳ accessibility tree (shadcn-audit collect)
  ❌ Look       AvatarImage class="object-contain" -> object-fit: cover (root *:[img]:object-cover outranks the image's class)
               vega: AvatarImage class="object-contain" -> object-fit: contain (cn-avatar-image's object-cover yields to className)
               Measured by hand with getComputedStyle on img[alt=@logo]: collect's STYLE_PROPS has no object-fit. A wide logo is cropped to its middle.
               ↳ bases/base/ui/avatar.tsx:31 + style-vega.css:78
shadcn audit · this PR
shadcn audit  ruby-ui/ruby_ui
  base eb120059  head f1864145  shadcn 968d8cb9
⚠️ Environment  font: "Inter Variable", "system-ui", -apple-system, "system-ui", "Segoe UI", Roboto, "Helvetica Neue", Arial, "sans-serif" vs "Inter Variable", sans-serif (light)
⚠️ Environment  font: "Inter Variable", "system-ui", -apple-system, "system-ui", "Segoe UI", Roboto, "Helvetica Neue", Arial, "sans-serif" vs "Inter Variable", sans-serif (dark)
✅ Theme  neutral tokens match shadcn
Avatar  (ref: bases/base/ui/avatar.tsx + style-vega.css @ 968d8cb9)
  ⏸ Look       properties: font-family
               Avatar, AvatarImage, AvatarFallback, AvatarBadge, AvatarGroup, AvatarGroupCount — explained by environment diff: font
  ✅ ARIA       Avatar, AvatarImage, AvatarFallback, AvatarBadge, AvatarGroup, AvatarGroupCount: accessibility tree matches
               ↳ accessibility tree (shadcn-audit collect)
  ✅ Look       AvatarImage class="object-contain" -> object-fit: contain
               Measured by hand with getComputedStyle on img[alt=@logo]: collect's STYLE_PROPS has no object-fit. The root styles only a plain img (no data-slot); AvatarImage owns its own look, as in shadcn.
               ↳ bases/base/ui/avatar.tsx:31 + style-vega.css:78

Testing

  • cd gem && bundle exec rake test: 796 runs, 0 failures.
  • cd audit && bundle exec rake test: 288 runs, 0 failures.
  • /shadcn-audit on this branch: the last avatar shows all three stripes of the logo, like shadcn.

🤖 Generated with Claude Code

Light

Dark


Summary by cubic

Fixes AvatarImage's className being ignored when the root Avatar applied object-cover to images, which cropped wide logos to their middle. The root now scopes its sizing and rounding to bare <img> children ([&>img:not([data-slot])]), so AvatarImage, which carries data-slot, styles itself and its class wins, matching shadcn. AvatarImage(class: "object-contain") now renders logos uncropped; a plain <img> passed directly into Avatar keeps its existing round, cropped sizing. Test and audit fixtures updated to cover the fixed case.