Unable to change `variant` props of DatePicker, TimePicker and DateTimePicker in 5.x
See original GitHub issueDescribe the bug
In the old version, we can use variant
or inputVariant
to change the variant of DatePicker, TimePicker and DateTimePicker.
In MUI 5.0, variant
is removed from DatePicker, TimePicker and DateTimePicker, so you should use renderInput
instead them. However renderInput
is already used by mui-rff, thus there is no way to change its variant.
To Reproduce For example
<DatePicker
variant="standard"
inputFormat="yyyy-MM-dd"
/>
If you use jsx, the variant
props is not work. The variant would be outlined not standard.
If you use typescript. This would cause error TS2769 (No overload matches this call).
Because variant
is removed from DatePicker.
Additional context
To solve this problem I modify DatePick.tsx
.
Add variant?: "standard" | "filled" | "outlined";
to DatePickerProps
and DatePickerWrapperProps
.
export interface DatePickerProps extends Partial<Omit<MuiDatePickerProps, "onChange">> {
name: string;
locale?: any;
fieldProps?: Partial<FieldProps<any, any>>;
required?: boolean;
variant?: "standard" | "filled" | "outlined";
showError?: ShowErrorFunc;
}
interface DatePickerWrapperProps extends FieldRenderProps<MuiDatePickerProps> {
required?: boolean;
variant?: "standard" | "filled" | "outlined";
locale?: any;
}
Add variant
props to the TextField
function DatePickerWrapper(props: DatePickerWrapperProps) {
const {
// ...
variant,
// ...
...rest
} = props;
// ...
return pickerProviderWrapper(
<MuiDatePicker
// ...
renderInput={(props) => (
<TextField
// ...
variant={variant}
// ...
/>
)}
/>,
locale
);
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
@mxt305 this should work
Solution is above, closing. Thanks for playing.