Skip to content

Commit 290d102

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.
1 parent a8fde4a commit 290d102

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
@@ -387,4 +387,27 @@ describe('ng-add schematic', () => {
387387
expect(buffer.toString()).toContain('<body class="one mat-typography two">');
388388
});
389389
});
390+
391+
it('should not add the global typography class if the user did not opt into it', async () => {
392+
appTree.overwrite('projects/material/src/index.html', `
393+
<html>
394+
<head></head>
395+
<body class="one two"></body>
396+
</html>
397+
`);
398+
399+
const tree = await runner.runSchematicAsync('ng-add-setup-project', {
400+
typography: false
401+
}, appTree).toPromise();
402+
403+
const workspace = getWorkspace(tree);
404+
const project = getProjectFromWorkspace(workspace);
405+
const indexFiles = getProjectIndexFiles(project);
406+
expect(indexFiles.length).toBe(1);
407+
408+
indexFiles.forEach(indexPath => {
409+
const buffer = tree.read(indexPath)!;
410+
expect(buffer.toString()).toContain('<body class="one two">');
411+
});
412+
});
390413
});

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)