Skip to content
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

[Typography] Make it easy to change the font-weight #12704

Closed
2 tasks done
verekia opened this issue Aug 29, 2018 · 15 comments
Closed
2 tasks done

[Typography] Make it easy to change the font-weight #12704

verekia opened this issue Aug 29, 2018 · 15 comments
Labels
component: Typography The React component. duplicate This issue or pull request already exists

Comments

@verekia
Copy link

verekia commented Aug 29, 2018

I believe there is currently no way to change the font-weight with Typography.

With Roboto, we have access to 4 font-weight variations:

  • Light
  • Normal
  • Bold
  • Bolder

When using <b> or <strong>, the browser defaults to the bolder variation (which is too bold and inelegant in my opinion). To use the bold font-weight: 500 or the light variation, we have to create custom styles.

It would be neat if Typography supported changing the font-weight, or if there was a FontWeight component of some sort.

I have implemented it here.

  • This is a v1.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Examples

Bold
screenshot 2018-08-30 00 03 24

Bolder
screenshot 2018-08-30 00 03 41

Comparison
screenshot 2018-08-30 00 10 41

@oliviertassinari oliviertassinari added this to the v3.x milestone Aug 29, 2018
@oliviertassinari oliviertassinari added the new feature New feature or request label Aug 29, 2018
@ssalka
Copy link

ssalka commented Aug 29, 2018

FWIW, I would expect such a feature to work as follows:

const enum FontWeight {
  Light = 300,
  Normal = 400,
  ...
}

interface TypographyProps {
  // possibly just "weight" for simplicity?
  fontWeight?: FontWeight;
  ...
}

const LightText = props => <Typography fontWeight={FontWeight.Light} {...props} />;

where any (valid) value passed to the fontWeight prop would override font-weight styles that come from e.g. the variant prop

@eps1lon
Copy link
Member

eps1lon commented Aug 30, 2018

I believe there is currently no way to change the font-weight with Typography.

There is with withStyles. https://codesandbox.io/s/oqvyznjw6z

You could also change the variants globally with a custom theme.

I'm skeptic about a component that should handle all possible typography related css properties. withStyles and custom theming is flexible enough to do that already.

@verekia
Copy link
Author

verekia commented Aug 31, 2018

@eps1lon and don't you think that's a lot of code just to make something bold?

With withStyles you don't have to do it on Typography you can apply the class to a <span>, or a <strong> or <b> for better semantic, but that's way too much code to achieve something so common and simple in my opinion. It's just that Typography is where that feature should be implemented.

Italics don't have variations so <em> or <i> are fine.

And text-decoration: underline is not as common as font weight variations I think.

@eps1lon
Copy link
Member

eps1lon commented Aug 31, 2018

I think that this component should only implement the material design typography spec. The spec lists different variants with various combinations of weight and size. Everything beyond that should belong into userland and can be done easily thanks to reacts composition model.

@oliviertassinari oliviertassinari modified the milestones: v3.x, v4 Feb 18, 2019
@oliviertassinari oliviertassinari removed this from the v4 milestone Apr 17, 2019
@oliviertassinari oliviertassinari added the priority: important This change can make a difference label Apr 17, 2019
@eps1lon
Copy link
Member

eps1lon commented Jul 9, 2019

I think this is covered by our Box component and <Box fontWeight={500} />.

@oliviertassinari Do you think we can close this issue or is there something else we could do?

@verekia
Copy link
Author

verekia commented Jul 9, 2019

Box looks great, that definitely solves the problem for bold text.

That being said I think a good addition to Box could be text-decoration, mostly for underline and strikethrough:
https://www.w3schools.com/cssref/tryit.asp?filename=trycss_text-decoration

If you think that's relevant it could probably be moved to a different issue though.

@eps1lon
Copy link
Member

eps1lon commented Jul 9, 2019

That being said I think a good addition to Box could be text-decoration, mostly for underline and strikethrough:

New properties can be proposed via PR to https://github.com/mui-org/material-ui/blob/5b25ed3bb0c3639f8ce8204e20ab1e354f63bde2/packages/material-ui-system/src/typography.js#L36

@oliviertassinari
Copy link
Member

@eps1lon I think that using the system in the core components would completely solve the issue: #15561. +1 for closing this one.

@eps1lon eps1lon closed this as completed Jul 9, 2019
@aprilmintacpineda
Copy link

Still not easy as of today. Suggested approach https://material-ui.com/system/typography/#main-content does not seem to work.

@BiggA94
Copy link

BiggA94 commented Nov 8, 2019

@aprilmintacpineda

The best approach to have both is currently using a Box with fontweight and inside it, use a typography with fontweight: inherit.


const styles = (theme: Theme) => createStyles({
    boldTypography: {
        fontWeight: 'inherit',
    }
});

... render() {
  <Box fontWeight="fontWeightBold">
    <Typography className={this.props.classes.boldTypography}>
      I'm Bold
    </Typography>
  </Box>
}
...

@aprilmintacpineda
Copy link

@BiggA94 fontWeight="fontWeightBold" would be unnecessary in your example, you can just use fontWeight: <Value>, right?

@louiidev
Copy link

Please, this would be great and would make a lot of sense, just to pass a prop to the Typography component

@oliviertassinari oliviertassinari added duplicate This issue or pull request already exists and removed new feature New feature or request priority: important This change can make a difference labels May 11, 2020
@ydax
Copy link

ydax commented Jun 22, 2020

Agree with Louis, though I do find that I often just need to make parts of Typography Components bold, which complicates things. Would it be possible to handle normal HTML styling tags inside Typography components? E.g.:
<Typography>Howdy, <strong>I'm bold</strong> but I'm not.</Typography>

@alexandermckay
Copy link

alexandermckay commented Jul 28, 2020

This will work:

  <p>
    Hello
    <Box component="span" fontWeight={700}>
      world
    </Box>
  </p>

https://codesandbox.io/s/bitter-haze-kwnrv?file=/src/App.tsx

@oliviertassinari oliviertassinari added the component: Typography The React component. label Nov 13, 2020
@oliviertassinari
Copy link
Member

@alexandermckay In v5, you will get:

<Typography sx={{ fontWeight: 'bold' }} />

where bold is taken from theme.typography.fontWeightBold, 700 by default. One part is dependent on #17615. Would it solve the pain?

@oliviertassinari oliviertassinari changed the title Make it easy to change the font-weight [Typograpy] Make it easy to change the font-weight Nov 13, 2020
@oliviertassinari oliviertassinari changed the title [Typograpy] Make it easy to change the font-weight [Typography] Make it easy to change the font-weight Nov 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Typography The React component. duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

9 participants