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.

[Datepicker] [Timepicker] Can't override placeholder text due to input format

See original GitHub issue
  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

Passing placeholder to renderInput does not do anything due to input format.

Expected Behavior 🤔

Placeholder on renderInput should be passed to input, rather than input format if placeholder is passed.

Steps to Reproduce 🕹

    <TimePicker
        renderInput={props => (
          <TextField
            {...props}
            helperText="override works today"
            placeholder="override does nothing"
          />
        )}
        label={'Label'}
        // This is forced placeholder text
        inputFormat={'h:mm a'}
      />

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
Aeon-Industriescommented, Apr 18, 2022

@sherlock2017

Still, this isn’t working, can anyone help!

This appears to be the correct way of doing it. Date/time pickers put the placeholder directly into inputProps - attributes applied to the input element (not to be confused with InputProps, which are Input component props), so we have to override that.

<LocalizationProvider dateAdapter={AdapterDateFns} style={{ width: "40px" }}>
  <TimePicker
    value={time}
    onChange={setTime}
    renderInput={({ inputProps, ...restParams }) => (
      <TextField
        {...restParams}
        inputProps={{
          ...inputProps,
          placeholder: "Add Class Time",
        }}
        style={{ width: "198px" }}
      />
    )}
  />
</LocalizationProvider>

Posting for clarification since the approach is somewhat counter-intuitive, and the first post example is misleading.

1reaction
sherlock2017commented, Apr 8, 2022

<LocalizationProvider dateAdapter={AdapterDateFns} style={{ width: "40px" }} > <TimePicker value={time} onChange={setTime} renderInput={(params) => ( <TextField placeholder="Add Class Time" {...params} style={{ width: "198px" }} /> )} /> </LocalizationProvider>

image

Still, this isn’t working, can anyone help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Datepicker] [Timepicker] Can't override placeholder text due ...
This appears to be the correct way of doing it. Date/time pickers put the placeholder directly into inputProps - attributes applied to the...
Read more >
How to set the placeholder text of the MUI 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 :...
Read more >
How to set placeholder value for input type date in HTML 5
The placeholder attribute does not work with the input type Date, so place any value as a placeholder in the input type Date....
Read more >
DatePicker - Ant Design
To select or input a date. ... Time. Switchable picker. Switch in different types of pickers by Select. ... We can set the...
Read more >
Form Datepicker | Components - BootstrapVue
BootstrapVue custom date picker input form control, which provides full WAI-ARIA ... Add custom placeholder text to the control, when no date is...
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