Material-ui: [Typography] Custom font family

Created on 2 Mar 2018  路  6Comments  路  Source: mui-org/material-ui

I would like to use Product Sans in the project, but Typography component uses Roboto by default and can't be changed.

  • [ ] I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

product sans

Current Behavior

roboto

Steps to Reproduce (for bugs)

Codesandbox link

  1. Go to the codesandbox page.
  2. Inspect the title element and go to the typography class (for example, '.MuiTypography-display1-15')
  3. Uncheck the css row that contains font family (font-family: "Roboto", "Helvetica", "Arial", sans-serif;)
  4. Now you can see what Product Sans looks like in the title.

Context

I would like to use the new typography from Google. I know that, at this point, using Product Sans in Material Design it's not "official" but I think it would be a good idea to have the flexibility to choose what fonts to use in the Typography element.

Your Environment

| Tech | Version |
|--------------|---------|
| Material-UI | 1.0.0-beta.35 |
| React | 16.2.0 |
| browser | Chrome 64.0.3282.186 |

Typography question

Most helpful comment

Typography component uses Roboto by default and can't be changed

@urkopineda It can be changed. The best solution is to use the option we provide to do so. It's documented:
https://material-ui-next.com/customization/themes/#typography

const theme = createMuiTheme({
  typography: {
    fontFamily: '"Product Sans", serif',
  },
});

All 6 comments

Typography component uses Roboto by default and can't be changed

@urkopineda It can be changed. The best solution is to use the option we provide to do so. It's documented:
https://material-ui-next.com/customization/themes/#typography

const theme = createMuiTheme({
  typography: {
    fontFamily: '"Product Sans", serif',
  },
});

Typography component uses Roboto by default and can't be changed

@urkopineda It can be changed. The best solution is to use the option we provide to do so. It's documented:
https://material-ui-next.com/customization/themes/#typography

const theme = createMuiTheme({
  typography: {
    fontFamily: '"Product Sans", serif',
  },
});

This method has limit however. When I apply theme to the root component, it applied to the root component and its direct children, however, deeply nested components that are imported by children component did not inherit the theme. In a large app, it would be nice to apply the theme once in one root component rather then many time in many components. Can this feature be improved to have a global and private scope?

however, deeply nested components that are imported by children component did not inherit the theme

@huyvlam It should be working, it's the nominal use case. We don't encourage the creation of many theme providers in the application.

@oliviertassinari Indeed, found the issue: I used ThemeProvider as a wrapper, and inside I included MuiCSSBaseline like this:

<ThemeProvider><Grid><MuiCSSBaseline /></Grid></ThemeProvider>

I was able to make it work buy rearraning them like: .

Thanks for your help.

@huyvlam rearranging them like how?

@huyvlam rearranging them like how?

<Grid>
  <MuiCSSBaseline />
  <ThemeProvider>
    <PageComponent/>
  </ThemeProvider>
</Grid>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

revskill10 picture revskill10  路  3Comments

mb-copart picture mb-copart  路  3Comments

iamzhouyi picture iamzhouyi  路  3Comments

activatedgeek picture activatedgeek  路  3Comments

ryanflorence picture ryanflorence  路  3Comments