fix(material/datepicker): prevent crash during range picker navigation #31969
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #31959
What's the issue?
The date range picker crashes when you select a start date and then use arrow keys to navigate to the next month. You get this error:
What was causing it?
The tracking function in the calendar wasn't handling month changes properly. When you navigate between months, Angular gets confused about which DOM elements to keep and which to remove.
How I fixed it
I updated the
_trackRow
function to create more stable tracking keys by combining the row index with the first cell's value. This way Angular can properly track elements when the month changes.Changed files:
calendar-body.ts
- Fixed the tracking functioncalendar-body.html
- Updated template to use the new function signaturemonth-view.spec.ts
- Added a test to make sure this doesn't break againTesting
This is a small, targeted fix that doesn't change any public APIs or break existing functionality.