Skip to content

fix: icon baseline alignment #9661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 9, 2025
Merged

fix: icon baseline alignment #9661

merged 7 commits into from
Jul 9, 2025

Conversation

jouni
Copy link
Member

@jouni jouni commented Jul 8, 2025

Add an explicit baseline alignment element to the shadow DOM, since both pseudo elements are already used.

Before:
Screenshot 2025-07-08 at 15 17 44

After:
Screenshot 2025-07-08 at 15 17 30

@@ -72,6 +72,7 @@ class Icon extends IconMixin(ElementMixin(LumoInjectionMixin(ThemableMixin(Polyl
/** @protected */
render() {
return html`
<span class="baseline"></span>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we instead covert this span to wrap <svg> and set display: contents on it e.g. like this?

  .icon {
    display: contents;
  }

  .icon::before {
    content: '\\2003';
    display: inline-block;
    width: 0;
  }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I suppose we can. But why?

Copy link
Member

@web-padawan web-padawan Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that dedicated wrapper would feel a bit more natural, but I'm not 100% sure.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note about this "hack" 🥸 #6950

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, thanks for bringing this up. I guess it should be ok for a standalone vaadin-icon itself but maybe it could be a problem for icon inside a button if screen readers announce that pseudo-element.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was more hoping for a fix if you guys try to include this in more components 😏 just searched 2003 in this repo made my realize how common this pattern is.. with such a simple fix "/ ''" available

Copy link
Member Author

@jouni jouni Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I'd also forgotten about that issue (I think I’ve seen it before). I somehow have assumed that the extra space wouldn't cause an issue, more than a slightly longer pause in the reading. But I suppose even that is problematic.

We can at least add the content: '\2003' / '' fix, but I’m not sure how well that is supported. I remember reading that screen readers don't necessarily use it. But according to MDN, Safari 17.4 has support, which is good enough for V25: https://developer.mozilla.org/en-US/docs/Web/CSS/content#browser_compatibility

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we fix it in a separate PR for #6950.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the fix for case already.

@web-padawan
Copy link
Member

Icon visual test with font icons failed and the alignment does not look correct there:

font-icons

@jouni
Copy link
Member Author

jouni commented Jul 8, 2025

Right, I didn't test that yet, so good that tests caught it.

@jouni
Copy link
Member Author

jouni commented Jul 9, 2025

Icon visual test with font icons failed and the alignment does not look correct there:

Should be fixed now.

@jouni
Copy link
Member Author

jouni commented Jul 9, 2025

I’ll update the CSS version of Lumo.

@web-padawan web-padawan force-pushed the fix/icon-baseline-alignment branch from cb726d9 to 05c271f Compare July 9, 2025 08:26
Copy link
Member

@web-padawan web-padawan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased and removed one more display: inline-block override on the vaadin-icon.

Copy link

sonarqubecloud bot commented Jul 9, 2025

@web-padawan web-padawan merged commit e024063 into main Jul 9, 2025
10 checks passed
@web-padawan web-padawan deleted the fix/icon-baseline-alignment branch July 9, 2025 08:39
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.

3 participants