Skip to content

Commit fd3f028

Browse files
authored
fix(material/icon): false positive in font detection (#33805)
Fixes some false positives when trying to detect which icon font is loaded.
1 parent b1645e6 commit fd3f028

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

‎src/material/icon/icon-registry.ts‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -743,26 +743,28 @@ function isSafeUrlWithOptions(value: any): value is SafeResourceUrlWithIconOptio
743743

744744
/** Infers which font classes to apply by default based on the fonts that have been loaded. */
745745
function inferDefaultFontSetClass(document: Document): string[] {
746-
let materialSymbolsVariantion: 'outlined' | 'rounded' | 'sharp' | null = null;
746+
let materialSymbolsVariation: 'outlined' | 'rounded' | 'sharp' | null = null;
747747
let hasLegacyMaterialIcons = false;
748748

749749
// Note that this approach only detects the fonts that are link tags at the time of calling
750750
// so we may miss some fonts that are loaded later. That should be a minority and the logic
751751
// below still falls back to the old behavior if that happens.
752752
if (document.fonts && typeof document.fonts.forEach === 'function') {
753-
document.fonts.forEach(({family}) => {
754-
if (family.includes('Material Icons')) {
753+
document.fonts.forEach(font => {
754+
const family = font.family.replace(/['"]/g, '').trim().toLowerCase();
755+
756+
if (family === 'material icons' || family.startsWith('material icons ')) {
755757
hasLegacyMaterialIcons = true;
756758
}
757759

758-
if (family.includes('Material Symbols Rounded')) {
759-
materialSymbolsVariantion = 'rounded';
760-
} else if (family.includes('Material Symbols Sharp')) {
761-
materialSymbolsVariantion = 'sharp';
762-
} else if (family.includes('Material Symbols')) {
760+
if (family.startsWith('material symbols rounded')) {
761+
materialSymbolsVariation = 'rounded';
762+
} else if (family.startsWith('material symbols sharp')) {
763+
materialSymbolsVariation = 'sharp';
764+
} else if (family.startsWith('material symbols')) {
763765
// This should mostly catch `Material Symbols Outlined`,
764766
// but we keep it a bit broader just in case.
765-
materialSymbolsVariantion = 'outlined';
767+
materialSymbolsVariation = 'outlined';
766768
}
767769
});
768770
}
@@ -772,8 +774,8 @@ function inferDefaultFontSetClass(document: Document): string[] {
772774
// however this ends up being very breaking internally, because some apps were loading both
773775
// without setting the correct class. We play it safe here so we can at least handle the class
774776
// automatically for new apps.
775-
materialSymbolsVariantion && !hasLegacyMaterialIcons
776-
? `material-symbols-${materialSymbolsVariantion}`
777+
materialSymbolsVariation && !hasLegacyMaterialIcons
778+
? `material-symbols-${materialSymbolsVariation}`
777779
: 'material-icons',
778780
'mat-ligature-font',
779781
];

0 commit comments

Comments
 (0)