Search code examples
javascriptreactjsdatepickermaterial-ui

How to remove border of Material UI's DatePicker?


Here is the datepicker component

import React, { Fragment, useState } from "react";
import {
  KeyboardDatePicker,
  MuiPickersUtilsProvider
} from "@material-ui/pickers";
import DateFnsUtils from "@date-io/date-fns";
import makeStyles from "@material-ui/styles/makeStyles";

const useStyles = makeStyles({
  root: {
    "& .MuiInputBase-root": {
      padding: 0, 
      "& .MuiButtonBase-root": {
        padding: 0,
        paddingLeft: 10
      },
      "& .MuiInputBase-input": {
        padding: 15,
        paddingLeft: 0
      }
    }
  }
});

function InlineDatePickerDemo(props) {
  const [selectedDate, handleDateChange] = useState(new Date());
  const classes = useStyles();

  return (
    <MuiPickersUtilsProvider utils={DateFnsUtils}>
      <KeyboardDatePicker
        className={classes.root}
        autoOk
        variant="inline"
        inputVariant="outlined"
        label="With keyboard"
        format="MM/dd/yyyy"
        value={selectedDate}
       InputAdornmentProps={{ position: "start" }}
        onChange={(date) => handleDateChange(date)}
      />
    </MuiPickersUtilsProvider>
  );
}

export default InlineDatePickerDemo;

From codeSandbox Link can anyone tell how to remove border from all sides ? Although I managed to know that .MuiInput-underline:before style class is responsible for border width but dont know where to put that class in makeStyles.


Solution

  • You just need to edit a bit the KeyboardDatePicker element:

    1. Remove inputVariant="outlined"

    2. Add

    InputProps={{
      disableUnderline: true
    }}
    

    CodeSandbox