angular / angular/components

bug(datepicker): input parse validation broken on custom DateAdapter<numeric>

Open
#26,554 0 comments 0 reactions 0 assignees View on GitHub
area: material/datepicker P3
Dominant language
TypeScript
Stars
25k
Forks
6.8k
Avg merge
1d 8h
Merged PRs (30d)
91

Description

### Is this a regression?

- [ ] Yes, this behavior used to work in the previous version

### The previous version in which this bug was not present was

_No response_

### Description

Falsy check of value within [datepicker-input-base._isValidValue](https://github.com/angular/components/blob/a1d5614f18066c0c2dc2580c7b5099e8f68a8e74/src/material/datepicker/datepicker-input-base.ts#L382) leads to invalid numeric date values from custom DateAdapter to be treated as valid instead:
```javascript
! 0
// -> true
! NaN
// -> true
```
-> [parseValidator](https://github.com/angular/components/blob/a1d5614f18066c0c2dc2580c7b5099e8f68a8e74/src/material/datepicker/datepicker-input-base.ts#L150) will never return a 'matDatepickerParse' error.

### Reproduction

Steps to reproduce:
1. Use Custom DateAdapter which returns NaN on invalid()
2. Enter invalid characters on the datepicker's input.
3. Leave datepicker

### Expected Behavior

validation error ('format error') shown/raised.

### Actual Behavior

No error validation error ('format error') will be shown/raised.

([datepicker-input-base._isValidValue](https://github.com/angular/components/blob/a1d5614f18066c0c2dc2580c7b5099e8f68a8e74/src/material/datepicker/datepicker-input-base.ts#L382) should check for 'null' | 'undefined' instead of falsy)

### Environment

- Angular: 15.0.4
- CDK/Material: 15.0.4
- Browser(s): Chrome
- Operating System (e.g. Windows, macOS, Ubuntu): Windows

Contributor guide

Open the contributing guide

Research direction

Start in src/material/datepicker/datepicker-input-base.ts, especially _isValidValue and parseValidator. Reproduce the issue with a numeric custom DateAdapter that returns NaN for invalid input, then verify that entering invalid characters and leaving the datepicker produces a matDatepickerParse validation error.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.