How to remove border of Material UI's DatePicker?

Viewed 6246

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.

4 Answers

You just need to edit a bit the KeyboardDatePicker element:

  1. Remove inputVariant="outlined"

  2. Add

InputProps={{
  disableUnderline: true
}}

CodeSandbox

in MUI you can add variant="standard" to TextField :

 renderInput={(params) => <TextField variant="standard" {...params} />}

completely :

 <DesktopDatePicker
                inputFormat="MM/dd/yyyy"
                className="mt-0 w-100"
                required={required}
                margin="normal"
                id="date-picker-dialog"
                label={label}
                format="dd/MM/yyyy"
                value={value}
                onChange={handleDateChange}
                renderInput={(params) => <TextField variant="standard" {...params} />}
            />

It's just necessary to remove inputVariant="outlined" props. So your code becomes:

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

Here your code modified.

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