admin管理员组文章数量:1390949
I recently upgraded from @mui/x-date-pickers v6 to v7, and my DateTimeField component stopped working due to a TypeScript error.
In v6, I was able to add a custom button to open the calendar using endAdornment inside slotProps.textField.InputProps, but in v7, this approach throws a TypeScript error.
Here's my component code:
<DateTimeField
className={classes.dateTimeField}
value={value}
onChange={handleDateTimeFieldChange}
format={DATE_FORMAT}
slotProps={{
textField: {
error: Boolean(errorMessage),
InputProps: {
endAdornment: (
<IconButton
className={classes.openCalendarButton}
onClick={handleOpenCalendar}
title="Open calendar"
size="small"
>
<CalendarWithClockIcon />
</IconButton>
),
},
},
}}
/>
This code worked fine in v6 but now results in the following TypeScript error in v7:
Type '{ className: string; value: Dayjs; onChange: (newDate: Dayjs) => void; format: string; slotProps: { textField: { error: boolean; InputProps: { endAdornment: Element; }; }; }; }'
is not assignable to type 'Omit<Omit<FilledTextFieldProps | OutlinedTextFieldProps | StandardTextFieldProps, "select" | "type" | ... 7 more ... | "SelectProps">, keyof UseDateTimeFieldProps<...>>'.
Types of property 'slotProps' are incompatible.
Type '{ textField: { error: boolean; InputProps: { endAdornment: React.JSX.Element; }; }; }'
is not assignable to type '{ input?: SlotProps<ElementType<FilledInputProps, keyof IntrinsicElements>, {}, BaseTextFieldProps> | undefined; inputLabel?: SlotProps<...> | undefined; htmlInput?: SlotProps<...> | undefined; formHelperText?: SlotProps<...> | undefined; select?: SlotProps<...> | undefined; } | { ...; } | { ...; } | undefined'.ts(2322)
I tried different approaches, but I couldn't find a simple solution.
Question: What is the correct way to add an endAdornment button in DateTimeField in @mui/x-date-pickers v7?
Any help would be greatly appreciated!
I recently upgraded from @mui/x-date-pickers v6 to v7, and my DateTimeField component stopped working due to a TypeScript error.
In v6, I was able to add a custom button to open the calendar using endAdornment inside slotProps.textField.InputProps, but in v7, this approach throws a TypeScript error.
Here's my component code:
<DateTimeField
className={classes.dateTimeField}
value={value}
onChange={handleDateTimeFieldChange}
format={DATE_FORMAT}
slotProps={{
textField: {
error: Boolean(errorMessage),
InputProps: {
endAdornment: (
<IconButton
className={classes.openCalendarButton}
onClick={handleOpenCalendar}
title="Open calendar"
size="small"
>
<CalendarWithClockIcon />
</IconButton>
),
},
},
}}
/>
This code worked fine in v6 but now results in the following TypeScript error in v7:
Type '{ className: string; value: Dayjs; onChange: (newDate: Dayjs) => void; format: string; slotProps: { textField: { error: boolean; InputProps: { endAdornment: Element; }; }; }; }'
is not assignable to type 'Omit<Omit<FilledTextFieldProps | OutlinedTextFieldProps | StandardTextFieldProps, "select" | "type" | ... 7 more ... | "SelectProps">, keyof UseDateTimeFieldProps<...>>'.
Types of property 'slotProps' are incompatible.
Type '{ textField: { error: boolean; InputProps: { endAdornment: React.JSX.Element; }; }; }'
is not assignable to type '{ input?: SlotProps<ElementType<FilledInputProps, keyof IntrinsicElements>, {}, BaseTextFieldProps> | undefined; inputLabel?: SlotProps<...> | undefined; htmlInput?: SlotProps<...> | undefined; formHelperText?: SlotProps<...> | undefined; select?: SlotProps<...> | undefined; } | { ...; } | { ...; } | undefined'.ts(2322)
I tried different approaches, but I couldn't find a simple solution.
Question: What is the correct way to add an endAdornment button in DateTimeField in @mui/x-date-pickers v7?
Any help would be greatly appreciated!
Share Improve this question edited Mar 18 at 0:16 Olivier Tassinari 8,6916 gold badges25 silver badges28 bronze badges asked Mar 14 at 21:46 Калдар КайратКалдар Кайрат 133 bronze badges1 Answer
Reset to default 0In @mui/x-date-pickers v7, the slotProps.textField.InputProps
prop is deprecated. You can use slots.textfield
prop instead. Check the example below
版权声明:本文标题:reactjs - How to add endAdornment button in DateTimeField after migrating to @muix-date-pickers v7? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744631174a2616547.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论