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

Asteriks class for TextField #14490

Closed
e11en opened this issue Feb 11, 2019 · 7 comments
Closed

Asteriks class for TextField #14490

e11en opened this issue Feb 11, 2019 · 7 comments
Labels
component: text field This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process. new feature New feature or request

Comments

@e11en
Copy link

e11en commented Feb 11, 2019

FormControlClassKey does not include the ability to add a class to the asterisk set by the required prop of a TextField.

I would like to be able to do:

<TextField classes={{asterisk: 'asterisk'}} />

...

'.asterisk': { color: 'blue' }

Current situation has no ability to do this and in my styling I need to do this:

'> label > span': { color: 'blue' }
@oliviertassinari oliviertassinari added support: question Community support but can be turned into an improvement component: text field This is the name of the generic UI component, not the React module! labels Feb 11, 2019
@oliviertassinari
Copy link
Member

@e11en Here you go:

import React from "react";
import PropTypes from "prop-types";
import { withStyles } from "@material-ui/core/styles";
import TextField from "@material-ui/core/TextField";

const styles = theme => ({
  asterisk: {
    color: "red"
  }
});

function TextFields(props) {
  const { classes } = props;

  return (
    <form noValidate autoComplete="off">
      <TextField
        required
        InputLabelProps={{
          FormLabelClasses: {
            asterisk: classes.asterisk
          }
        }}
        id="standard-required"
        label="Required"
        defaultValue="Hello World"
        margin="normal"
      />
    </form>
  );
}

TextFields.propTypes = {
  classes: PropTypes.object.isRequired
};

export default withStyles(styles)(TextFields);

https://codesandbox.io/s/kxvv9w085r

capture d ecran 2019-02-11 a 11 38 01

@oliviertassinari oliviertassinari added new feature New feature or request good first issue Great for first contributions. Enable to learn the contribution process. and removed support: question Community support but can be turned into an improvement labels Feb 11, 2019
@oliviertassinari
Copy link
Member

But yeah, we could add an asterisk style rule to the InputLabel component so you can do:

      <TextField
        required
        InputLabelProps={{
          classes: {
            asterisk: classes.asterisk
          }
        }}
        id="standard-required"
        label="Required"
        defaultValue="Hello World"
        margin="normal"
      />

instead. Do you want to work on it? :)

@e11en
Copy link
Author

e11en commented Feb 11, 2019

Ah yeah of course! I didn't think of that way of adding the class name. Thanks! I'll have a look at adding that style rule

@eps1lon
Copy link
Member

eps1lon commented Feb 11, 2019

FormLabel docs are also missing a comment about the asterisk class. It is listed as a class key but not explanation about the purpose: https://material-ui.com/api/form-label/#css

@umairfarooq44
Copy link
Contributor

@e11en @oliviertassinari If anyone is not working on this, would love to make PR. Thanks

@oliviertassinari
Copy link
Member

@umairfarooq44 We would be honored to review your pull request :)

@umairfarooq44
Copy link
Contributor

@oliviertassinari thanks for assigning issue. The solution should be in InputLabel component remove FormLabelClasses and use only classes from props. As FormLabelClasses and classes are two props for same purpose. Also asterisk should be included in documentation of InputLabel css API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: text field This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process. new feature New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants