Material-ui: How to style InputLabel through theme?

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

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

Expected Behavior


theme.typography.caption and theme.typography.body1 should be used for styling InputLabel (the first or the second depending on shrink).

Current Behavior


Defining theme.typography.caption.letterSpacing = '0.04em' doesn't show any effect on a <TextField InputLabelProps={{ shrink: true }} label="Some label" />.

Steps to Reproduce (for bugs)

https://codesandbox.io/s/l78x53665l

  1. Create a theme with letterSpacing: '0.04em' for 'caption'
  2. Create a TextField with InputLabelProps={{ shrink = true }}
  3. See how the theme defined for 'caption' is not applied to the TextField label

Context


I'm trying to adapt material-ui to how my app looked before it.

Your Environment

| Tech | Version |
|--------------|---------|
| Material-UI | 1.0.0-beta.36 |
| React | 16.2.0 |
| browser | Google Chrome 64.0.3282.119 |

TextField question

Most helpful comment

theme.typography.caption and theme.typography.body1 should be used for styling InputLabel (the first or the second depending on shrink).

@gustavopch I don't think that we can do that. First, we are transitioning the input label with the scale property. We will lose this capability. Then the specification doesn't ask for body1:

But more importantly, I'm not sure that sharing code between the two concepts is wise. I can create unexpected side effects. Instead, you can do the following:


const theme = createMuiTheme({
  typography: {
    body1: {
      letterSpacing: "0.4em"
    },
    caption: {
      letterSpacing: "0.4em"
    }
  },
  overrides: {
    MuiFormLabel: {
      root: {
        letterSpacing: "0.4em"
      }
    }
  }
});

https://codesandbox.io/s/68kly0oww
capture d ecran 2018-03-12 a 13 56 53

All 2 comments

theme.typography.caption and theme.typography.body1 should be used for styling InputLabel (the first or the second depending on shrink).

@gustavopch I don't think that we can do that. First, we are transitioning the input label with the scale property. We will lose this capability. Then the specification doesn't ask for body1:

But more importantly, I'm not sure that sharing code between the two concepts is wise. I can create unexpected side effects. Instead, you can do the following:


const theme = createMuiTheme({
  typography: {
    body1: {
      letterSpacing: "0.4em"
    },
    caption: {
      letterSpacing: "0.4em"
    }
  },
  overrides: {
    MuiFormLabel: {
      root: {
        letterSpacing: "0.4em"
      }
    }
  }
});

https://codesandbox.io/s/68kly0oww
capture d ecran 2018-03-12 a 13 56 53

@oliviertassinari Thank you. Your suggestion will do it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mattmiddlesworth picture mattmiddlesworth  路  3Comments

FranBran picture FranBran  路  3Comments

sys13 picture sys13  路  3Comments

reflog picture reflog  路  3Comments

activatedgeek picture activatedgeek  路  3Comments