palantir/blueprint

DateInput default settings can easily crash application in dev mode

Open

#4,251 创建于 2020年7月29日

在 GitHub 查看
 (2 评论) (3 反应) (0 负责人)TypeScript (20,263 star) (2,167 fork)batch import
P2Package: datetimeType: enhancementhelp wanted

描述

Summarizing a collection of grievances in https://github.com/palantir/blueprint/issues/3394, https://github.com/palantir/blueprint/issues/2965, https://github.com/palantir/blueprint/issues/3407, and other issues:

Environment

  • Package version(s): datetime 3.18.5
  • Operating System: macOS
  • Browser name and version: any

Code Sandbox

From @barrymay in https://github.com/palantir/blueprint/issues/3394#issuecomment-665406086:

https://codesandbox.io/s/angry-morse-hn3rm?file=/src/App.js

To see the problem:

  • Enter 1/1/1999. Hit 'enter'

Actual behavior

Page crashes during validateProps() lifecycle method

Expected behavior

Page does not crash, instead we get some nicer out-of-the-box error handling like the docs example:

2020-07-29 13 52 03

Possible solution

The developer has provided a valid parseDate function, but since they are using the default values of minDate and maxDate set by the component, they are not able to properly validate whether the entered date is out of bounds. Another option would be to wrap the component in an ErrorBoundary, but that's clunky and heavy-handed.

In general I think users should be setting their own minDate and maxDate bounds. But since we have already set the defaults in the API I think we should improve the developer experience here without breaking the API.

贡献者指南