我正在使用Material UI Pickers
,但是当我尝试编辑单个字符时,它将进入编辑模式,并且先前的值被清除,我必须从头开始输入日期
Here is a test case show this issue:
测试用例来自Material UI demo page
我的预期行为是,我可以在编辑时更改单个字符,我应该指出,这种行为确实在Material UI
的演示站点中有效,但是创建测试用例无法重现相同的结果
答案 0 :(得分:1)
我使用了date-fns库并导入了波斯语区域设置:
import React, { useState } from "react";
import DateFnsUtils from "@date-io/date-fns";
import format from "date-fns/format";
import faLocale from "date-fns/locale/fa-IR";
import {
KeyboardDatePicker,
MuiPickersUtilsProvider
} from "@material-ui/pickers";
class LocalizedUtils extends DateFnsUtils {
getDatePickerHeaderText(date) {
return format(date, "P", { locale: this.locale });
}
}
const InlineDateTimePickerDemo = props => {
const [selectedDate, handleDateChange] = useState(new Date());
return (
<MuiPickersUtilsProvider utils={LocalizedUtils} locale={faLocale}>
<KeyboardDatePicker
clearable
format="mm/dd/yyyy"
value={selectedDate}
onChange={date => handleDateChange(date)}
minDate={new Date()}
/>
</MuiPickersUtilsProvider>
);
};
export default InlineDateTimePickerDemo;