Ankita Ray
Ankita Ray

Reputation: 53

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.

Upvotes: 5

Views: 17072

Answers (6)

haroon kiani
haroon kiani

Reputation: 329

Try this in CSS . add the below code into your CSS, it really worked for me. Thanks

.MuiOutlinedInput-notchedOutline {
  border: none ! important ;
}

Upvotes: 0

Anoop Kumar
Anoop Kumar

Reputation: 488

With MUI Datepicker version 6 and above we need to use slotProps. Adding sample code below:

<DatePicker
    label="Date of Birth"
    value={account.dob}
    onChange={inputsHandler}
    sx={{ width: "100%" }}
    slotProps={{ textField: { variant: 'standard', } }}  {/** set variant here */}
/>

Upvotes: 11

Samira
Samira

Reputation: 2723

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} />}
            />

Upvotes: 3

Alvaro
Alvaro

Reputation: 2059

You just need to edit a bit the KeyboardDatePicker element:

  1. Remove inputVariant="outlined"

  2. Add

InputProps={{
  disableUnderline: true
}}

CodeSandbox

Upvotes: 6

n--
n--

Reputation: 3856

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

Upvotes: 4

Giovanni Esposito
Giovanni Esposito

Reputation: 11156

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.

Upvotes: 1

Related Questions