Skip to content

Comments

Add start and end slots to <wa-badge>#2082

Open
lindsaym-fa wants to merge 7 commits intonextfrom
lm/icons-in-badges
Open

Add start and end slots to <wa-badge>#2082
lindsaym-fa wants to merge 7 commits intonextfrom
lm/icons-in-badges

Conversation

@lindsaym-fa
Copy link
Contributor

@lindsaym-fa lindsaym-fa commented Feb 19, 2026

Closes #2072 by:

  • Removing styles for slotted <wa-icon> elements in favor of start and end slots for opt-in, reliable styling.
  • Adding vertical-align: middle to <wa-badge> for consistent alignment regardless of the badge's content. (The original styles attempted to accommodate this by resizing slotted icons.)

Why Slots?

The initial code I set out to remove was, in part, applying margin-inline-end: var(--wa-space-2xs, 0.25em) to slotted icons. This is needlessly opinionated and fragile; it assumes icons are only placed before other badge content.

Elsewhere, we do try CSS-only solutions to apply default icon spacing according to whether the icon is at the beginning or end of the supplied content. Take this example from <wa-tab>:

::slotted(wa-icon:first-child) {
  margin-inline-end: 0.5em;
}

::slotted(wa-icon:last-child) {
  margin-inline-start: 0.5em;
}

But this doesn't actually work. Because content in the default slots of components like <wa-tab> are typically plain text nodes, including <wa-icon> means that the icon matches both :first-child and :last-child. i.e., we get this:
Screenshot 2026-02-19 at 6 37 12 PM

Slots give us much more reliable control of spacing, so it felt like the best approach for <wa-badge> and seems worth considering for other components, too.

@claviska, I'm 100% open to pushback if you think this is overkill!

@lindsaym-fa lindsaym-fa linked an issue Feb 19, 2026 that may be closed by this pull request
@vercel
Copy link

vercel bot commented Feb 19, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
webawesome Ready Ready Preview Feb 19, 2026 11:53pm

Request Review

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.

Icons within badges are styled

1 participant