Skip to content

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

Description

@mjewell

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions