Skip to content

Commit 2b83a0a

Browse files
crisbetojelbourn
authored andcommitted
fix(schematics): global typography class always being added (#18315)
In #17602 a new prompt to `ng-add` was added which allowed consumers to opt into adding the `mat-typgoraphy` style globally, but it looks like the option was never read so the class is always being added. Fixes #16776. (cherry picked from commit 290d102)
1 parent 964de7b commit 2b83a0a

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/material/schematics/ng-add/index.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,4 +384,27 @@ describe('ng-add schematic', () => {
384384
expect(buffer.toString()).toContain('<body class="one mat-typography two">');
385385
});
386386
});
387+
388+
it('should not add the global typography class if the user did not opt into it', async () => {
389+
appTree.overwrite('projects/material/src/index.html', `
390+
<html>
391+
<head></head>
392+
<body class="one two"></body>
393+
</html>
394+
`);
395+
396+
const tree = await runner.runSchematicAsync('ng-add-setup-project', {
397+
typography: false
398+
}, appTree).toPromise();
399+
400+
const workspace = getWorkspace(tree);
401+
const project = getProjectFromWorkspace(workspace);
402+
const indexFiles = getProjectIndexFiles(project);
403+
expect(indexFiles.length).toBe(1);
404+
405+
indexFiles.forEach(indexPath => {
406+
const buffer = tree.read(indexPath)!;
407+
expect(buffer.toString()).toContain('<body class="one two">');
408+
});
409+
});
387410
});

src/material/schematics/ng-add/theming/theming.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ export function addTypographyClass(options: Schema): (host: Tree) => Tree {
5757
throw new SchematicsException('No project index HTML file could be found.');
5858
}
5959

60-
projectIndexFiles.forEach(indexFilePath => addBodyClass(host, indexFilePath, 'mat-typography'));
60+
if (options.typography) {
61+
projectIndexFiles.forEach(path => addBodyClass(host, path, 'mat-typography'));
62+
}
6163

6264
return host;
6365
};

0 commit comments

Comments
 (0)