question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to change `variant` props of DatePicker, TimePicker and DateTimePicker in 5.x

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
kybargcommented, Nov 18, 2021

@mxt305 this should work

<DatePicker  TextFieldProps={{ variant: 'standard' }} />
0reactions
lookfirstcommented, Sep 15, 2022

Solution is above, closing. Thanks for playing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Ultimate MUI v5 DatePicker and TimePicker Tutorial (Plus ...
MUI DatePicker Variants. In Material-UI v4, the DatePicker had a variant prop for changing the component styling and behavior. For example, the ...
Read more >
Material UI DateTimePicker Rendering In Wrong Spot
I am rendering a new material ui date time picker immediately on page render by enabling the open prop.
Read more >
react-native-community/datetimepicker - npm
React Native date & time picker component for iOS, ... Allows overriding system theme variant (dark or light mode) used by the date...
Read more >
Migration from @material-ui/pickers - MUI
The state/value management logic for pickers was rewritten from scratch. Pickers will now call the onChange prop when each view of the date...
Read more >
React 17 Material-UI Datepicker and Timepicker Example ...
There are a number of UI components provided by Material UI package modules. To use a component we first import it in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found