fix(action-button): track label content changes after first render - #6586
fix(action-button): track label content changes after first render#6586rubencarvalho wants to merge 3 commits into
Conversation
ActionButton's default slot wasn't bound to the SlotTextController's handleSlotChange, so hasLabel only reflected content present at connect. Dynamically adding/removing the label in a consumer app left the --iconOnly class stale. Button, Badge, IllustratedMessage, and Card already bind this correctly; ActionButton was the outlier.
🦋 Changeset detectedLatest commit: e37c893 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
📚 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 |
Coverage Report for CI Build 31117883006Warning No base build found for commit Coverage: 96.239%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats💛 - Coveralls |
Description
<swc-action-button>'s default<slot>wasn't bound toSlotTextController'shandleSlotChange.hasLabel(and therefore theswc-ActionButton--iconOnlyclass) was only correct for content present at connect; label text added or removed afterward wasn't tracked.Motivation and context
SlotTextControllerrequires the observed slot to bind@slotchangefor post-first-render changes to be tracked (itsMutationObserveronly watchescharacterData, notchildList).swc-button,swc-badge,swc-illustrated-message, andswc-cardall bind this correctly;swc-action-buttonwas the one outlier, so a consumer app that dynamically clears or sets an action button's label (e.g. a framework re-render) would see the button stay icon-only-styled (or vice versa) with stale spacing until an unrelated property change forced a re-render.I audited every consumer of
SlotTextController(Button.base.ts,Badge.base.ts,IllustratedMessage.base.ts,Card.base.ts) and their concrete render templates;ActionButton.tswas the only one missing the binding.CloseButtonoverrideshasIcon/hasLabeldirectly and doesn't use the controller, so it's unaffected.Related issue(s)
Author's checklist
Reviewer's checklist
patch,minor, ormajorfeaturesManual review test cases
Dynamic label removal collapses to icon-only
Action button > Tests > Dynamic label behavior<swc-action-button><svg slot="icon">...</svg>Edit</swc-action-button>, then remove the text node)<button>to gainswc-ActionButton--iconOnlyand tighten its paddingDynamic label addition restores label layout
swc-ActionButton--iconOnlyto be removed and label spacing to returnDevice review
Accessibility testing checklist
Keyboard (required — document steps below)
Screen reader (required — document steps below)
accessible-label/visible text combination — the fix only corrects the internal--iconOnlystyling class, notaria-labelderivation, which was already correct.