Repository navigation
Conversation
Badge passed `style` to the `slds-badge__icon` span instead of the badge itself, so without `icon` the prop was silently ignored. The prop is documented as custom styles for the badge, and the class component before the rewrite described it as "Custom styles to be passed to the component", but it had the same bug. `style` now goes on the root `slds-badge` span. The new `styleIcon` prop styles the icon container, so callers that relied on the old behavior have a direct replacement. BREAKING CHANGE: Badge's `style` prop now styles the badge element instead of the icon container. To keep styling the icon container, pass those styles as `styleIcon`.
Badge had no tests. `style` lands on the badge with and without an icon, and `styleIcon` lands on the icon container.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #
Additional description
Symptom
Badge applies
styleto the icon container instead of the badge itself. Withouticon,styleis silently ignored, so there is no way to style the badge element through its ownstyleprop.Root cause
stylewas passed to the icon container span incomponents/badge/index.tsx.The prop is documented as custom styles for the badge, and the class component before the rewrite described it as "Custom styles to be passed to the component", but it had the same bug. So this is not a regression from #3195.
This is also listed in the v11 prop API freeze review in ROADMAP.md ("
stylecurrently lands on the icon span, not the root").Change
stylenow goes on the root badge span.styleIconprop styles the icon container, so callers that relied on the old behavior have a direct replacement.Breaking change
stylenow styles the badge element instead of the icon container. To keep styling the icon container, pass those styles asstyleIcon. The fix commit has aBREAKING CHANGEfooter.The ROADMAP prefers
className*for parts other than the root. If you would rather not add a newstyle*prop, I can switchstyleIcontoclassNameIconor drop it.Tests
Added three cases to
badge.test.jsx, next to the tests from feat(badge): add info color variant for SLDS parity #3229.stylelands on the badge when there is no icon.stylelands on the badge and not on the icon container when there is an icon.styleIconlands on the icon container.No story uses
style, so there is no snapshot change.CONTRIBUTOR checklist (do not remove)
Please complete for every pull request.
Green gate — all of these must pass locally (CI runs the same):
npm run lintpasses with 0 errors (npm run lint:fixto auto-fix). Warnings are the tracked gradual-migration backlog; do not add new errors.npm run typecheckis clean (tsc --noEmit).npm test -- --runpasses — this runs both Vitest projects (jsdomunit+ real-browserbrowser) and the story HTML snapshots. If you changed rendered markup on purpose, update snapshots withnpm test -- --run -uand review the diff.npm run buildsucceeds (type-check + Vite library build +.d.ts+ entry shims).Behavior & docs:
components/button/__tests__). New props and bug fixes should get a regression test. Tests that genuinely need a real browser (focus traversal, layout/measurement, canvas) go in a*.browser.test.jsxfile (thebrowserproject); everything else is jsdom.npm run storybook→ http://localhost:6007/. Confirm the story actually renders and behaves (deprecated Storyshots/Karma are gone; there is no separate browser-tests server).onRenderContent/onRenderVisualPicker,iconprops,events), not assumptions — a common source of "component looks broken" reports has been stories authored against the wrong API. Cross-check againstcomponents/<name>/__examples__..d.ts(they're generated by the build); JS consumers rely on them via editor type-acquisition.REVIEWER checklist (do not remove)
CIworkflow: lint, typecheck, test, build). Chromatic visual review, if configured, has been checked.components/__tests__/__snapshots__/story-snapshots.test.jsx.snap).@salesforce/design-system-react/components/<name>and nested paths resolve for ESM, CJS, and types). Removing/renaming a public component or export is a breaking change →feat!:/BREAKING CHANGE:and a major version bump.