Declined
Last Updated: 15 Oct 2021 05:18 by ADMIN
Brent
Created on: 14 Oct 2021 17:30
Category: KendoReact
Type: Bug Report
0
DateTimePicker Throws Exception Opening Calendar For Invalid Date

Repro:

  1. Create a DateTimePicker.
  2. Use its value prop to programmatically control the value the control uses.
  3. Add clickable Button (or other means) to programmatically set the value to an invalid date (i.e. something like new Date("invalid!").
  4. Click the Button.  The date displayed becomes "NaN/NaN/NaN 12:NaN PM".  I suppose this is reasonable.
  5. Now, click the calendar popup icon on the right-hand side of the component.

Expected:

Displays a calendar popup, perhaps defaulting to the current date & time.

Actual:

Throws an exception visible in the JavaScript console.  Replaces the UI with an error message.

Proof-of-Concept:

https://stackblitz.com/edit/react-gvipiu?file=app%2Fmain.tsx


import * as React from 'react';
import * as ReactDOM from 'react-dom';

import {
  DateTimePicker,
  DateTimePickerChangeEvent,
} from '@progress/kendo-react-dateinputs';
import { Button } from '@progress/kendo-react-buttons';

const App = () => {
  const [date, setDate] = React.useState(new Date());

  const handleChange = (event: DateTimePickerChangeEvent) => {
    setDate(event.value);
  };

  const handleClick = () => {
    setDate(new Date('invaild!'));
  };

  return (
    <React.Fragment>
      <div className="example-wrapper">
        <p>
          (use Alt+<code>↓</code> to open the date-time selector, <code>←</code>{' '}
          and <code>→</code> to navigate, <code>↑</code> to increment and{' '}
          <code>↓</code> to decrement the value)
        </p>
        <DateTimePicker onChange={handleChange} value={date} />
      </div>
      <Button onClick={handleClick}>
        Click me, then the calendar, to break the DateTimePicker.
      </Button>
      <div>{date?.toString()}</div>
    </React.Fragment>
  );
};

ReactDOM.render(<App />, document.querySelector('my-app'));
Important note: This POC code uses version 4.9.0 of kendo-react-buttons.  I do not know what that translates to in terms of the "version" dropdown.  I can't tell if "2021.1.119" is applicable here.
1 comment
ADMIN
Stefan
Posted on: 15 Oct 2021 05:18

Hello, Brent,

Thank you for the example and all of the steps.

This is expected as the component expects a valid JavaScript Date object as a value. This can be seen in the API:

https://www.telerik.com/kendo-react-ui/components/dateinputs/api/DateTimePickerProps/#toc-value

Passing invalid values to the component is expected to lead to different errors. The developer has to ensure that a valid value is passed to the component.

Regards,
Stefan
Progress Telerik

Remote troubleshooting is now easier with Telerik Fiddler Jam. Get the full context to end-users' issues in just three steps! Start your trial here - https://www.telerik.com/fiddler-jam.