How do I change the style of a prop in <TextField>?

Viewed 97

I'm rendering <TextField> twice using my defined DatePicker.js component. So, whenever the user clicks on the <CalendarIcon> which is inside the <TextField>, small calendar will open up. I want to style the label in the <TextField> in a specific way. Currently, this is how it looks.

enter image description here
You can see that 'To' label of the second <TextField> is visible. It should come behind the calendar and should not show up.

class DatePickerInput extends React.Component {
  render() {
    const {
      classes,
      label,
      selectedDate
    } = this.props;
    return (<TextField
        fullWidth
        variant="filled"
        label={label}
        onClick={this.props.onClick}
        value={selectedDate.format("MM-DD-YYYY")}
        InputLabelProps={{
          shrink: true
        }}
        InputProps={{
          className: classes.input,
          endAdornment: (<CalendarIcon color="primary" />)
        }}
      />)
  }
}
class DatePicker extends React.Component {

  render() {
    const {
      label,
      value,
      minDate,
      maxDate,
      onChange
    } = this.props;


    return (
      <ReactDatePicker
        selected={value.toDate()}
        minDate={minDate.toDate()}
        maxDate={maxDate.toDate()}
        customInput={<DatePickerInputComp
          selectedDate={value}
          label={label}
        />}
        onChange={onChange} />
    )
  }
}

The problem:
How do I make the 'To' label not show up when the <CalendarIcon> pops up. I want to style the prop 'label' of TextField but I'm not sure of how I can do it.

The Updated Code:

const inputStyles = theme => ({
  icon: {
     zIndex: 1029,
   },
});
class DatePicker extends React.Component {

  render() {
    const {
      label,
      value,
      minDate,
      maxDate,
      onChange,
    } = this.props;
    const { classes } = this.props;


    return (
      <ReactDatePicker
        selected={value.toDate()}
        minDate={minDate.toDate()}
        maxDate={maxDate.toDate()}
        customInput={<DatePickerInputComp
          selectedDate={value}
          label={label}
        />}
        wrapperClassName={classes.icon}
        onChange={onChange} />
    )
  }
}
1 Answers

You can add a higher z index for the react-datepicker component in order to make it visible at the top stack.

 <ReactDatePicker
    selected={value.toDate()}
    minDate={minDate.toDate()}
    maxDate={maxDate.toDate()}
    customInput={<DatePickerInputComp
    selectedDate={value}
    label={label}
    wrapperClassName="datePicker"
  />

I've added a wrapperClassname datePicker in order to make the styling easier.

.datePicker{
 z-index: 999
}

Temporarily gave the z-index as 999, You can alter it to a lower value after defining a z-index for the text field.

Related