Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateInput onClose raises e.replace is not a function #676

Open
mjewell opened this issue Mar 31, 2020 · 1 comment
Open

DateInput onClose raises e.replace is not a function #676

mjewell opened this issue Mar 31, 2020 · 1 comment

Comments

@mjewell
Copy link
Contributor

mjewell commented Mar 31, 2020

Using a DateInput with onClose causes parse to be called with a Date, but it seems like it is expected to only be called with a string:

import { dateParse } from 'js-utils-apm';

function Example() {
  const [date, setDate] = useState('');
  return <DateInput
    dateFormat="MM/DD/YYYY"
    parse={dateParse}
    onChange={setDate}
    value={date}
    onClose={console.log}
  />;
}

The error comes from this line: https://github.com/appfolio/react-gears/blob/v5.7.2/src/components/DateInput.js#L249

It can be fixed by handling the case where the value is a date:

parse={(dateOrString: string | Date) => {
  if (dateOrString instanceof Date) {
    return dateOrString;
  }
  return dateParse(dateOrString);
}}

We should either change it so parse is expected to handle being given a Date or a string, or change it so parse does not get called when the value is a Date.

@ztmeyer
Copy link
Contributor

ztmeyer commented Apr 1, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants