fix(action-button): show swc-avatar inside swc-action-button - #6587
Conversation
Replaces the placeholder <button> TODO in the "In Action button" story with the real <swc-action-button>. The avatar goes in the default slot rather than slot="icon": ActionButton's icon-slot CSS forces the slotted element's box to a fixed icon-size token, which fights Avatar's own self-sizing (--swc-avatar-size) and causes the image to overflow its squeezed host. Putting it in the default slot lets Avatar size itself normally. The avatar is marked decorative since the visible "Jane Doe" text (or the button's accessible-label in the icon-only variant) already identifies the person. Adds a second icon-only example (avatar with no visible label) using accessible-label, alongside the labeled one.
The wrapper span defaulted to vertical-align: baseline, misaligning it against the button's line box by a couple pixels versus the icon-only example. Setting vertical-align: middle matches how Avatar's own host aligns itself.
🦋 Changeset detectedLatest commit: 5635d69 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Shows the same labeled and icon-only pairing at the xl action-button size, with the avatar scaled to size="400" to match the larger button height.
| <span | ||
| style="display: inline-flex; align-items: center; gap: 8px; vertical-align: middle;" | ||
| > | ||
| <swc-avatar |
There was a problem hiding this comment.
Should these be placed in the icon slot instead? ✨
<swc-avatar>'s internal image/background previously sized themselves directly from --swc-avatar-size, independent of the host element's own box. ActionButton's icon-slot CSS forces the slotted element's inline-size/block-size to match its own icon-size token via a higher-specificity rule than Avatar's :host([size]) selector, which already won the fight for the host's box (confirmed via computed styles), but had no effect on the visible avatar because the internal image ignored the host box and kept its own explicit size, causing it to overflow its squeezed container. Avatar's :host now sizes itself from --swc-avatar-size (as before), and the internal .swc-Avatar/.swc-Avatar-image simply fill 100% of the host. Any external rule that overrides the host's inline-size/ block-size (like ActionButton's icon slot) now scales the visible avatar with it, with no name-specific coupling between the two components and no size pairing required by consumers. Updates the avatar "In Action button" story to put the avatar back in slot="icon" (rather than the default slot workaround), and adds an xl action-button example using the same avatar size="500" as the default example, to demonstrate that consumers no longer need to coordinate avatar size with action-button size.
Reverts the previous avatar.css architecture change (making the host box canonical and having internal elements fill 100%) in favor of a more targeted fix: ActionButton's icon slot now sets --swc-avatar-size directly, the same way it already sets its own internal --_swc-action-button-icon-size custom properties. Verified empirically that this override wins over Avatar's own :host([size="x"]) rule for a slotted avatar, despite that rule having higher selector specificity by the usual (a,b,c) calculation - shadow tree cascade resolution for rules matching via ::slotted() does not follow same-tree specificity comparison the same way. Confirmed via computed styles: the same <swc-avatar size="500"> now resolves --swc-avatar-size to 18px inside an "m" action button and 22px inside "xl", with no changes to Avatar's own CSS architecture and no size-pairing required from consumers. Also updates the auto-generated global-action-button.css mirror and adds a note to avatar.mdx's "In Action button" section documenting that the avatar's size attribute is a no-op in that context.
📚 Branch Preview Links🔍 Gen1 Visual Regression Test ResultsWhen a visual regression test fails (or has previously failed while working on this branch), its results can be found in the following URLs:
Deployed to Azure Blob Storage: If the changes are expected, update the |
Avatar's size attribute is a no-op when slotted into an action button's icon slot, so authoring it in the example would misleadingly suggest it matters.
Coverage Report for CI Build 31192439901Warning Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes. Coverage remained the same at 96.241%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
| .swc-ActionButton-icon { | ||
| color: inherit; | ||
| fill: currentcolor; | ||
| --swc-avatar-size: var(--_swc-action-button-icon-size); |
There was a problem hiding this comment.
Did this come from the generator or hand generated?
There was a problem hiding this comment.
global-component styles are auto-generated!
|
|
||
| **fix(action-button):** A `<swc-avatar>` slotted into `<swc-action-button>`'s `icon` slot now automatically scales to match the button's icon size. | ||
|
|
||
| Previously, Avatar's own `size` attribute controlled its rendered size regardless of the action button's size, since Avatar's `:host([size])` sizing rule won the specificity contest with the icon slot's generic sizing rule for the avatar's _host box_ only — the visible image inside Avatar's shadow root ignored that squeeze entirely and rendered at its own `size`, causing it to overflow. Consumers previously had to manually pair an avatar `size` with the action-button `size` (e.g. `xl` action button with avatar `size="1000"`) to avoid a visual mismatch. |
There was a problem hiding this comment.
Great call! I even added this to the vrt permutations :)
There was a problem hiding this comment.
I'm glad that I did because I found another bug!!!!
Lit still leaves its child-part boundary marker, a comment node <!--?lit$…$--> with non-empty data as a direct light-DOM child of <swc-action-button>. With no slot attribute, it lands in the default slot.
Then in slot-text-controller.ts, checkInitialContent() classifies nodes as element-or-text:
if (el.tagName) { … } // elements
if (this.slotName) return false; // named slots
return node.textContent ? node.textContent.trim().length > 0 : false; // ← comment falls hereA comment node has no tagName, so it hits the last branch, and node.textContent returns the comment's data (?lit$…$) → trims to non-empty → hasLabel = true → iconOnly = false.
5t3ph
left a comment
There was a problem hiding this comment.
Looks good, nice updates to VRTs.
One nit on placement of the avatar size cp.
|
|
||
| /* Lets a slotted <swc-avatar> track the icon slot's own size instead of | ||
| requiring consumers to pair its size attribute with the button's size. */ | ||
| --swc-avatar-size: var(--_swc-action-button-icon-size); |
There was a problem hiding this comment.
Perhaps make this more explicitly scoped to ::slotted(swc-avatar)
There was a problem hiding this comment.
applied the recommendation!
…l-styles VRT The 'Avatar icon' row's icon-only case only rendered at the default size, unlike its labeled counterpart above it which already loops over every size.
Description
Fixes
<swc-avatar>so it automatically scales to match<swc-action-button>'s icon size when slotted into itsiconslot. Also updates Avatar's "In Action button" story to demonstrate the fix, including a newxlaction-button example.Motivation and context
This started as a docs-only change: replacing the placeholder
<button>(with aTODO: Replace <button> with <swc-action-button> once that component is migrated to 2nd-gencomment) in Avatar's "In Action button" story with the real<swc-action-button>.That surfaced a real bug. Putting
<swc-avatar>in ActionButton'sslot="icon"didn't work: Avatar's ownsizeattribute controlled its rendered size regardless of the action button's size, so an avatar sized for one button size looked wrong (overflowed or clipped) in another. Avatar's size scale (16–104px) also doesn't line up with ActionButton's icon-size tokens, so there was nosizevalue that coincidentally fixed it — consumers would have been on the hook for manually pairing an avatarsizewith the action-buttonsize(e.g.xlaction button ↔ avatarsize="1000").The fix: ActionButton's icon slot now also sets
--swc-avatar-sizedirectly, the same way it already sets its own internal--_swc-action-button-icon-sizecustom properties for the slotted element. This wins over Avatar's own:host([size])rule for a slotted avatar. Confirmed empirically via computed styles: the same<swc-avatar size="500">now resolves--swc-avatar-sizeto18pxinside anmaction button and22pxinside anxlaction button, matching each button's own icon-size token exactly, with no changes to Avatar's own CSS architecture and no size-pairing required from consumers. Avatar'ssizeattribute simply becomes a no-op in this context (documented inavatar.mdx).The story now shows four examples side by side, none of which write a
sizeattribute on the avatar at all (it would be misleading to suggest it matters, since it's a no-op here):maction button, avatar + visible label (avatarslot="icon",decorative)maction button, avatar-only (icon-only), usingaccessible-labelfor the accessible namexlaction button, avatar + visible labelxlaction button, avatar-only(Earlier revisions of this PR had all four avatars share an explicit
size="500"to demonstrate the fix; that was removed once confirmed, since authoring a no-op attribute in the example would suggest it does something.)The avatar is marked
decorative(alt="") in all four since ActionButton doesn't automatically mark icon-slot contentaria-hidden, and the avatar's ownalttext would otherwise duplicate the button's visible/accessible name — matching Avatar's own documented guidance fordecorative.Related issue(s)
Author's checklist
Existing test suites pass unchanged: avatar (14/14), action-button (19/19), including custom-property/global-style VRT coverage checks (37/37 total across
components/avatarandcomponents/action-button).Reviewer's checklist
patch,minor, ormajorfeaturesManual review test cases
Avatar scales to match action-button icon size, no manual size pairing needed
Avatar > Docs, scroll to Behaviors > In Action buttonm, twoxl), each avatar rendered as a full circle with no clipping/overflow, correctly sized to each button's own icon-size token — even though every avatar uses the samesize="500"attributeStandalone avatar sizing is unaffected
Avatar > Docs > Options > SizesandOutlinestoriesIcon-only avatar action buttons have a correct accessible name
<button>to carryaria-label="Jane Doe"forwarded from the host'saccessible-labelattributeDevice review
Accessibility testing checklist
Keyboard (required — document steps below)
<swc-action-button>usage — the avatar itself is non-interactive and not part of the tab order.Screen reader (required — document steps below)
decorative/alt=""in every case.accessible-label. Both should sound identical to a screen reader user.