Skip to content
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

fix(material/icon): mat-icon misaligned when text-spacing is applied #29686

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

essjay05
Copy link
Contributor

@essjay05 essjay05 commented Sep 3, 2024

Fixes an issue with Angular Components Material Icon component where when text-spacing is applied the icon gets misaligned and if inside of an input or container with an outline, the icon gets cut off. This fix adds css styling to keep the icon middle-aligned when text-spacing is applied.

BEFORE screenshot
AFTER screenshot
AFTER screencast

Fixes b/250063405

@essjay05 essjay05 requested a review from a team as a code owner September 3, 2024 22:30
@essjay05 essjay05 requested review from amysorto and andrewseguin and removed request for a team September 3, 2024 22:30
@essjay05 essjay05 marked this pull request as draft September 3, 2024 22:37
@jelbourn jelbourn added the dev-app preview When applied, previews of the dev-app are deployed to Firebase label Sep 3, 2024
Copy link

github-actions bot commented Sep 3, 2024

Deployed dev-app for 6eedec6 to: https://ng-dev-previews-comp--pr-angular-components-29686-dev-shj4ulrd.web.app

Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt.

@essjay05 essjay05 marked this pull request as ready for review September 4, 2024 18:18
@essjay05 essjay05 force-pushed the fix-text-spacing-cutoff-icon branch 4 times, most recently from e516f0a to c2f58cf Compare September 18, 2024 17:59
@crisbeto
Copy link
Member

It seems like this causes the icons to bleed out from the button:
image

Is there a way that we can undo the text spacing just on icons instead?

@essjay05 essjay05 force-pushed the fix-text-spacing-cutoff-icon branch 2 times, most recently from b1faf18 to 4348041 Compare September 24, 2024 17:53
@essjay05 essjay05 force-pushed the fix-text-spacing-cutoff-icon branch from 4348041 to 7b43d83 Compare October 1, 2024 21:34
@essjay05
Copy link
Contributor Author

essjay05 commented Oct 1, 2024

It seems like this causes the icons to bleed out from the button: image

Is there a way that we can undo the text spacing just on icons instead?

I've made updates to the CSS to target icon to not be affected by text-spacing and it looks like it does somewhat help, but when really shrinking the window at certain points even the text spills out (as does the icons):
image
image

Open to any ideas/suggestions you may have @crisbeto.

@essjay05 essjay05 force-pushed the fix-text-spacing-cutoff-icon branch from 5ea9344 to 275d78e Compare October 2, 2024 17:00
@@ -45,6 +45,13 @@ mat-icon {
}
}

.mat-icon:has(div[style*='letter-spacing:']):has(div[style*='word-spacing:']) {
Copy link
Member

Choose a reason for hiding this comment

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

I think this will only work for inline styles.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made an update to be targeted similarly to overflow: visible, but the text-spacing styles applied by Parashu still seems to be overriding the .mat-icon !important styles.

I was wondering if it would be acceptable to hide the icons on mobile and add documentation that the icon will disappear so they will need to make sure the aria-label is appropriate even if the icon is missing? Let me know your thoughts @crisbeto.

@essjay05 essjay05 force-pushed the fix-text-spacing-cutoff-icon branch from 0570000 to 8bc3834 Compare October 3, 2024 21:32
.mat-grid-tile .mat-icon,
.mat-mdc-list-item .mat-icon,
.mat-mdc-list-option .mat-icon,
.mat-icon:has(div[style*='letter-spacing:']):has(div[style*='word-spacing:']) {
Copy link
Member

Choose a reason for hiding this comment

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

I think that we should drop the .mat-icon:has(div[style*='letter-spacing:']):has(div[style*='word-spacing:'] style. If there's some internal app setting these as inline styles, we should fix the app rather than our styles.

.mat-icon:has(div[style*='letter-spacing:']):has(div[style*='word-spacing:']) {
overflow: visible;
// Apply styles to avoid text spacing
letter-spacing: 0 !important;
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to add the !important? We can apply these as regular styles on mat-icon. If the app happens to be overriding them, it's on them to remove the overrides.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @crisbeto, I was attempting to have the specificity+!important override the injected stylesheet and/or user agent stylesheets which Parashu and Text Spacing Editor (Chrome extensions) applied styles since it looks like they both target * with letter-spacing, word-spacing, and line-height with !important flags. See Parashu override screenshot and Text Space Editor override screenshot for examples.

Regardless, it looks like if there are external/user agent stylesheets using !important that those are unable to be overridden according to this article I found.

I've gone ahead and removed the targets to inline-styles as well as the usage of !important based on your recommendations.

Let me know if I should change anything else.

@essjay05 essjay05 force-pushed the fix-text-spacing-cutoff-icon branch from 8bc3834 to 1901dea Compare October 7, 2024 21:56
@angular-robot angular-robot bot added the detected: breaking change PR contains a commit with a breaking change label Oct 7, 2024
src/material/icon/icon.scss Outdated Show resolved Hide resolved
src/material/icon/icon.scss Outdated Show resolved Hide resolved
src/material/button/button.scss Outdated Show resolved Hide resolved
// Undoes previous fix to Issue #11826 in preference of
// fixing to improve accessibility by not having the icon
// get cut off
overflow: visible;
Copy link
Member

Choose a reason for hiding this comment

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

I expect this to be quite breaking. Couldn't we resolve the issue by setting something like this?

.mat-mdc-button-base .mat-icon {
  flex-shrink: 0;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated based on recommendation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I expect this to be quite breaking. Couldn't we resolve the issue by setting something like this?

.mat-mdc-button-base .mat-icon {
  flex-shrink: 0;
}

Hi @crisbeto, I know you already approved this, but as I was going back and re-testing the approved changes on the buttons, the icons are still getting cut off on the bottom as you can see from this screencast. The flex-shrink: 0 only fixes the icon from being cropped/cutoff on the left/right, but not the bottom.

Let me know your thoughts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the latest change to add height: min-content to .mat-mdc-button-base .mat-icon to prevent the bottom of the icon from being cut off in buttons. Here are screenshots showing that it works with the updated height for with and without text-spacing applied:

No text-spacing screenshot
With text-spacing screenshot

@essjay05 essjay05 force-pushed the fix-text-spacing-cutoff-icon branch 2 times, most recently from e9c8daf to 4c0c338 Compare October 16, 2024 18:43
@essjay05 essjay05 force-pushed the fix-text-spacing-cutoff-icon branch 2 times, most recently from b3815cc to 151a279 Compare October 23, 2024 16:48
@essjay05 essjay05 force-pushed the fix-text-spacing-cutoff-icon branch 2 times, most recently from 5d1495b to ad5cb51 Compare October 30, 2024 17:02
Fixes an issue with Angular Components Material Icon component where
when text-spacing is applied the icon gets misaligned and if inside
of an input or container with an outline, the icon gets cut off.
This fix adds css styling  to keep the icon
middle-aligned when text-spacing is applied.

Fixes b/250063405
Updates styles for Angular Material Icon so when the icon is
within a button it sets the overflow to visible to avoid the
icon from being cutoff. Also updates the line-height to 1 set

Fixes b/250063405
Updates previous fix to move added styles to bottom of scss
file for overriding.

Fixes b/250063405
Updates classes to target .mat-icon usage in other Angular
Material Components (ie. list-item, list-option, grid-tile,
form-field, tab, toolbar, and tooltip).

Fixes b/250063405
Updates previous fix to target  instances where its
parent element has  or  applied to
it and to override any , , or
 changes to the  so it should stay the same.

Fixes b/250063405
Updates previous fix to Angular Material Icon component to
abide by the lint formatting.

Fixes b/250063405
Updates previous change to consolidate the important styles that
were added to ignore any externally placed text-spacing styles
be added to be targeted by all .mat-icon situations.

Fixes b/250063405
Updates previous fix to remove the inline targets and the usage
of forced usage of styles as it is on the app to remove any
overriding styles.

Fixes b/250063405

BREAKING CHANGE: removes use of forced styles

Updates the previous fix which uses "important" and removes it
as any overrides should be fixed by the app mat-icon is used in
instead.
Updates previous fix by updating documentation on the usage of
mat-icon within mdc-button to notify developers that mat-icon
is set to be hidden on mobile/xsmall screens to improve
accessibility and recommends the usage of aria-label or
aria-labelledby to notify screenreaders of the information that
mat-icon is supposed to convey.

Fixes b/250063405
Updates previous changes to icon.scss to remove unnecessary
specificity targeting and just moves classes to be generalized
under .mat-icon. Adds min-height and min-width to .mdc-button
so that when buttons (with icons especially) do not allow its
content to overflow outside of the button and maintaining its
accessibility by not allowing overlapping of text/content.

Fixes b/250063405
Updates notation to style change in icon.scss which undoes a previous
bug fix for GH issue angular#11826. As this change is now deemed as an
accessibility issue due to it being cut off/hidden.

Fixes b/250063405

BREAKING CHANGE: undoes hiding icon overflow

Reverts icon having its overflow visible to be more accessible.
…ext-spacing

Updates previous fix to revert removal of overflow: hidden to remove the breaking
change and updates the method of ensuring .mat-icon remains visible by applying
flex-shrink to it so the icon does not get cut off and improves accessibility.

Fixes b/250063405
Updates previous change to fix formatting for lint errors.
Updates previous fix to change .mat-mdc-button-base .mat-icon
from height: min-content to min-height: min-content to avoid
overriding the default .mat-icon height: 24px. This way it
defaults to min-content if the height becomes smaller than the
24px.

Fixes b/250063405
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
detected: breaking change PR contains a commit with a breaking change dev-app preview When applied, previews of the dev-app are deployed to Firebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants