键盘的Material UI填充输入

时间:2020-06-27 14:57:17

标签: material-ui

我知道,使用InputField可以传递variant="filled"道具来填充输入框。但是,是否还可以使用Material UI日期选择器(而不使用浏览器中的本机日期选择器)传递具有类似效果的道具?

输入示例:

enter image description here

1 个答案:

答案 0 :(得分:0)

我认为您正在寻找inputVariant={"filled"}道具

import "date-fns";
import React from "react";
import Grid from "@material-ui/core/Grid";
import DateFnsUtils from "@date-io/date-fns";
import {
  MuiPickersUtilsProvider,
  KeyboardTimePicker,
  KeyboardDatePicker
} from "@material-ui/pickers";

export default function MaterialUIPickers() {
  // The first commit of Material-UI
  const [selectedDate, setSelectedDate] = React.useState(
    new Date("2014-08-18T21:11:54")
  );

  const handleDateChange = date => {
    setSelectedDate(date);
  };

  return (
    <MuiPickersUtilsProvider utils={DateFnsUtils}>
      <Grid container justify="space-around">
        <KeyboardDatePicker
          inputVariant={"filled"}
          disableToolbar
          variant="inline"
          format="MM/dd/yyyy"
          margin="normal"
          id="date-picker-inline"
          label="Date picker inline"
          value={selectedDate}
          onChange={handleDateChange}
          KeyboardButtonProps={{
            "aria-label": "change date"
          }}
        />
      </Grid>
    </MuiPickersUtilsProvider>
  );
}

工作sandbox project link