Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the placeholder text of the MUI DatePicker?

How can I set the placeholder text of the MUI DatePicker. The text that is displayed when deleting the text in the input field. I want to set the text to "tt.mm.jjjj" and I always the following error message:

Format string contains an unescaped latin alphabet character `j`

Sandbox

<DatePicker
  inputFormat="tt.mm.jjjj"
    label="Basic example"
    value={value}
    onChange={(newValue) => {
      setValue(newValue);
    }}
    renderInput={(params) => <TextField placeholder="tt.mm.jjjj" {...params} />}
  />
like image 515
vuvu Avatar asked Sep 12 '25 16:09

vuvu


2 Answers

This is how you reset the placeholder of the TextField inside the DatePicker. The reason it doesn't work is because it is overridden by the params.inputProps provided by the DatePicker itself based on the inputFormat:

<DatePicker
  {...}
  inputFormat="tt.mm.yyyy"
  renderInput={(params) => {
    console.log(params);
    return (
      <TextField
        {...params}
        inputProps={{
          ...params.inputProps,
          placeholder: "tt.mm.jjjj"
        }}
      />
    );
  }}
/>

Codesandbox Demo

like image 134
NearHuscarl Avatar answered Sep 15 '25 07:09

NearHuscarl


If you don't need to customize TextField, You can just use slotProps attribute to set the placehoder value.

<DatePicker
    format="tt.mm.yyyy"
    label="Basic example"
    value={value}
    onChange={setValue}
    slotProps={{ textField: { placeholder: 'tt.mm.jjjj' } }}
/>
like image 39
ruwan800 Avatar answered Sep 15 '25 06:09

ruwan800