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.

customInput component with input child cannot be typed in

See original GitHub issue

When creating a date picker with a custom input component, typing into the input field auto-formats to the incorrect date. For example, if the following date is in the input field: 01/01/2019, backspacing twice will automatically change the date to 01/01/2020. Backspacing 3 more times changes the date to 01/01/2002.

This is my code that is experiencing the issue:

const MyForm = () => (
  <DateInput />
);

const DateInput = () => {
  const [test, setTest] = useState(new Date());
  return (
    <DatePicker selected={test} onChange={date => setTest(date)} customInput={<CustomInput />
  );
}

const CustomInput = ({value, onClick, onChange}) => (
  <input value={value} onClick={onClick} onChange={onChange} />
);

Oddly enough, when using the standard date picker (without the custom input), everything works as expected.

Below is a gif of what happens when backspacing in the date picker with a custom input component react-datepicker-issue

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:13
  • Comments:7

github_iconTop GitHub Comments

3reactions
L5eoneillcommented, Mar 16, 2020

Wow. When I tried this (onFocus) in custom input, the focus seemed to flicker back and forth from input to calendar at a crazy rate. Completely not working.

2reactions
ivanosevitchcommented, Jan 14, 2020

@antiold @benuleau you actually have to additionally pass down onFocus to the CustomInput to avoid this issue. The following code doesn’t reproduce the bug:

const DateInput = () => {
  const [test, setTest] = useState(new Date());
  return (
    <DatePicker selected={test} onChange={date => setTest(date)} customInput={<CustomInput />
  );
}

const CustomInput = ({value, onFocus, onChange}) => (
  <input value={value} onFocus={onFocus} onChange={onChange} />
);

This is not intuitive though, it ought to be somewhere in the documentation.

Using react-datepicker 2.10.1

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-hook-form v7 - Custom input warning Function ...
React-hook-form v7 - Custom input warning Function components cannot be given refs ; name="host" ; label="Adresse host *" ; error={errors.host} ;..
Read more >
Unable to type in input after adding value prop #8053 - GitHub
The problem was that i wrote a custom form component, which cloned all child inputs via mapChildren . However, the suggested defaultValue prop ......
Read more >
Custom input components - Sanity.io
This article will explore the pieces and steps necessary to create a custom input component from scratch.
Read more >
Creating a custom input component for Sanity Studio - YouTube
This video may contain code snippets or concepts that are specific to a previous version of Sanity Studio. In most cases, you can...
Read more >
Vue custom input - DEV Community ‍ ‍
Most of us have faced it: build a custom input component. ... The way Vue works is: the child component has props that...
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