Address nitpicks
This commit is contained in:
@@ -205,7 +205,6 @@ export function PeopleSearch({
|
|||||||
slotProps: {
|
slotProps: {
|
||||||
input: {
|
input: {
|
||||||
...inputProps,
|
...inputProps,
|
||||||
autoComplete: "off",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -23,6 +23,18 @@ import { EditableTimeField } from "./EditableTimeField";
|
|||||||
|
|
||||||
dayjs.extend(customParseFormat);
|
dayjs.extend(customParseFormat);
|
||||||
|
|
||||||
|
const timePickerPopperSx = {
|
||||||
|
"& .MuiPaper-root": {
|
||||||
|
width: "110px",
|
||||||
|
minWidth: "110px",
|
||||||
|
},
|
||||||
|
"& .MuiMultiSectionDigitalClockSection-item": {
|
||||||
|
justifyContent: "flex-start",
|
||||||
|
width: "100%",
|
||||||
|
textAlign: "left",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Props for DateTimeFields component
|
* Props for DateTimeFields component
|
||||||
*/
|
*/
|
||||||
@@ -353,19 +365,7 @@ export const DateTimeFields: React.FC<DateTimeFieldsProps> = ({
|
|||||||
}}
|
}}
|
||||||
slotProps={{
|
slotProps={{
|
||||||
openPickerButton: { sx: { display: "none" } },
|
openPickerButton: { sx: { display: "none" } },
|
||||||
popper: {
|
popper: { sx: timePickerPopperSx },
|
||||||
sx: {
|
|
||||||
"& .MuiPaper-root": {
|
|
||||||
width: "110px",
|
|
||||||
minWidth: "110px",
|
|
||||||
},
|
|
||||||
"& .MuiMultiSectionDigitalClockSection-item": {
|
|
||||||
justifyContent: "flex-start",
|
|
||||||
width: "100%",
|
|
||||||
textAlign: "left",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
field: getTimeFieldSlotProps(
|
field: getTimeFieldSlotProps(
|
||||||
"start-time-input",
|
"start-time-input",
|
||||||
false,
|
false,
|
||||||
@@ -411,19 +411,7 @@ export const DateTimeFields: React.FC<DateTimeFieldsProps> = ({
|
|||||||
}}
|
}}
|
||||||
slotProps={{
|
slotProps={{
|
||||||
openPickerButton: { sx: { display: "none" } },
|
openPickerButton: { sx: { display: "none" } },
|
||||||
popper: {
|
popper: { sx: timePickerPopperSx },
|
||||||
sx: {
|
|
||||||
"& .MuiPaper-root": {
|
|
||||||
width: "110px",
|
|
||||||
minWidth: "110px",
|
|
||||||
},
|
|
||||||
"& .MuiMultiSectionDigitalClockSection-item": {
|
|
||||||
justifyContent: "flex-start",
|
|
||||||
width: "100%",
|
|
||||||
textAlign: "left",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
field: getTimeFieldSlotProps(
|
field: getTimeFieldSlotProps(
|
||||||
"end-time-input",
|
"end-time-input",
|
||||||
!!validation.errors.dateTime,
|
!!validation.errors.dateTime,
|
||||||
@@ -510,19 +498,7 @@ export const DateTimeFields: React.FC<DateTimeFieldsProps> = ({
|
|||||||
}}
|
}}
|
||||||
slotProps={{
|
slotProps={{
|
||||||
openPickerButton: { sx: { display: "none" } },
|
openPickerButton: { sx: { display: "none" } },
|
||||||
popper: {
|
popper: { sx: timePickerPopperSx },
|
||||||
sx: {
|
|
||||||
"& .MuiPaper-root": {
|
|
||||||
width: "110px",
|
|
||||||
minWidth: "110px",
|
|
||||||
},
|
|
||||||
"& .MuiMultiSectionDigitalClockSection-item": {
|
|
||||||
justifyContent: "flex-start",
|
|
||||||
width: "100%",
|
|
||||||
textAlign: "left",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
field: getTimeFieldSlotProps(
|
field: getTimeFieldSlotProps(
|
||||||
"start-time-input",
|
"start-time-input",
|
||||||
false,
|
false,
|
||||||
@@ -556,19 +532,7 @@ export const DateTimeFields: React.FC<DateTimeFieldsProps> = ({
|
|||||||
}}
|
}}
|
||||||
slotProps={{
|
slotProps={{
|
||||||
openPickerButton: { sx: { display: "none" } },
|
openPickerButton: { sx: { display: "none" } },
|
||||||
popper: {
|
popper: { sx: timePickerPopperSx },
|
||||||
sx: {
|
|
||||||
"& .MuiPaper-root": {
|
|
||||||
width: "110px",
|
|
||||||
minWidth: "110px",
|
|
||||||
},
|
|
||||||
"& .MuiMultiSectionDigitalClockSection-item": {
|
|
||||||
justifyContent: "flex-start",
|
|
||||||
width: "100%",
|
|
||||||
textAlign: "left",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
field: getTimeFieldSlotProps(
|
field: getTimeFieldSlotProps(
|
||||||
"end-time-input",
|
"end-time-input",
|
||||||
!!validation.errors.dateTime,
|
!!validation.errors.dateTime,
|
||||||
|
|||||||
@@ -46,11 +46,6 @@ function EditableTimePickerField(props: GenericPickerFieldProps) {
|
|||||||
const parsedFormat = useParsedFormat();
|
const parsedFormat = useParsedFormat();
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
// Get onChange from internalProps to call directly when value changes
|
|
||||||
const onChange = internalProps.onChange as
|
|
||||||
| ((value: Dayjs | null) => void)
|
|
||||||
| undefined;
|
|
||||||
|
|
||||||
const getFormattedValue = useCallback(() => {
|
const getFormattedValue = useCallback(() => {
|
||||||
if (pickerContext.value == null) return "";
|
if (pickerContext.value == null) return "";
|
||||||
if (!pickerContext.value.isValid()) return "";
|
if (!pickerContext.value.isValid()) return "";
|
||||||
@@ -151,7 +146,7 @@ function EditableTimePickerField(props: GenericPickerFieldProps) {
|
|||||||
setInputValue(getFormattedValue());
|
setInputValue(getFormattedValue());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[pickerContext, getFormattedValue, onChange]
|
[pickerContext, pickerActions, getFormattedValue]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Commit pending input value when picker closes (after parseAndUpdateTime is defined)
|
// Commit pending input value when picker closes (after parseAndUpdateTime is defined)
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ export const DATETIME_FORMAT_WITHOUT_SECONDS = "YYYY-MM-DDTHH:mm";
|
|||||||
|
|
||||||
export const TIME_PARSE_FORMATS = ["HH:mm", "H:mm", "HHmm", "Hmm", "HH", "H"];
|
export const TIME_PARSE_FORMATS = ["HH:mm", "H:mm", "HHmm", "Hmm", "HH", "H"];
|
||||||
|
|
||||||
|
// Strict parsing mode - input must exactly match the provided format(s)
|
||||||
|
const STRICT_PARSING = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detect datetime format based on string length
|
* Detect datetime format based on string length
|
||||||
* @param datetime - Datetime string to analyze
|
* @param datetime - Datetime string to analyze
|
||||||
@@ -77,7 +80,7 @@ export function convertFormDateTimeToISO(
|
|||||||
|
|
||||||
/** Convert date + time strings → Dayjs */
|
/** Convert date + time strings → Dayjs */
|
||||||
export const toDateTime = (date: string, time: string): Dayjs => {
|
export const toDateTime = (date: string, time: string): Dayjs => {
|
||||||
const d = dayjs(date, "YYYY-MM-DD", true);
|
const d = dayjs(date, "YYYY-MM-DD", STRICT_PARSING);
|
||||||
if (!time) return d.startOf("day");
|
if (!time) return d.startOf("day");
|
||||||
const [h, m] = time.split(":").map(Number);
|
const [h, m] = time.split(":").map(Number);
|
||||||
return d.hour(h).minute(m).second(0).millisecond(0);
|
return d.hour(h).minute(m).second(0).millisecond(0);
|
||||||
@@ -108,7 +111,7 @@ export function parseTimeInput(
|
|||||||
trimmed = trimmed.padStart(4, "0");
|
trimmed = trimmed.padStart(4, "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsed = dayjs(trimmed, TIME_PARSE_FORMATS, true);
|
const parsed = dayjs(trimmed, TIME_PARSE_FORMATS, STRICT_PARSING);
|
||||||
if (parsed.isValid()) {
|
if (parsed.isValid()) {
|
||||||
const baseDate = currentDate || dayjs();
|
const baseDate = currentDate || dayjs();
|
||||||
return baseDate
|
return baseDate
|
||||||
|
|||||||
Reference in New Issue
Block a user