-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
base: main
Are you sure you want to change the base?
Conversation
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. |
8527fc2
to
2030bac
Compare
e516f0a
to
c2f58cf
Compare
b1faf18
to
4348041
Compare
4348041
to
7b43d83
Compare
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): Open to any ideas/suggestions you may have @crisbeto. |
5ea9344
to
275d78e
Compare
src/material/icon/icon.scss
Outdated
@@ -45,6 +45,13 @@ mat-icon { | |||
} | |||
} | |||
|
|||
.mat-icon:has(div[style*='letter-spacing:']):has(div[style*='word-spacing:']) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
0570000
to
8bc3834
Compare
src/material/icon/icon.scss
Outdated
.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:']) { |
There was a problem hiding this comment.
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.
src/material/icon/icon.scss
Outdated
.mat-icon:has(div[style*='letter-spacing:']):has(div[style*='word-spacing:']) { | ||
overflow: visible; | ||
// Apply styles to avoid text spacing | ||
letter-spacing: 0 !important; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
8bc3834
to
1901dea
Compare
75815cb
to
c421855
Compare
src/material/icon/icon.scss
Outdated
// Undoes previous fix to Issue #11826 in preference of | ||
// fixing to improve accessibility by not having the icon | ||
// get cut off | ||
overflow: visible; |
There was a problem hiding this comment.
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;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated based on recommendation.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
1c1680b
to
f6558d6
Compare
e9c8daf
to
4c0c338
Compare
b3815cc
to
151a279
Compare
151a279
to
5eb2043
Compare
5d1495b
to
ad5cb51
Compare
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
ad5cb51
to
6eedec6
Compare
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