Skip to content

fix(date-picker): avoid double overlay detach when destroyed while open - #17958

Open
ivanvpetrov wants to merge 4 commits into
masterfrom
ipetrov/fix-17938
Open

ivanvpetrov wants to merge 4 commits into
masterfrom
ipetrov/fix-17938

Conversation

@ivanvpetrov

Copy link
Copy Markdown
Contributor

Closes #17938

Description

Destroying an igx-date-picker or igx-date-range-picker while its calendar is open no longer logs igxOverlay.detach was called with wrong id.

  • In ngOnDestroy, both pickers now detach the calendar only if the overlay is still registered (getOverlayById). The grid already guards its overlays the same way.
  • ngOnDestroy now always resets _overlayId. The date range picker never cleared it before.

Motivation / Context

The calendar container is created in the picker's own ViewContainerRef. When the picker is destroyed, Angular destroys that container before it runs the picker's ngOnDestroy. The overlay service registers a destroy callback on components it attaches, so it detaches the calendar overlay at that point. It doesn't emit closed, so the picker still holds the old overlay id. The picker's ngOnDestroy then calls detach with that id, which no longer exists, and the service logs the warning.

In the grid this happens every time a date cell edit ends while the calendar is open (Alt + Arrow Down, then Enter or Escape), because ending the edit removes the editor's picker.

The overlay service's own detach-on-destroy behaviour is correct and stays as is.

Type of Change (check all that apply):

  • Bug fix
  • New functionality
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactoring (no functional changes)
  • Documentation
  • Demos
  • CI/CD
  • Tests
  • Changelog
  • Skills/Agents

Component(s) / Area(s) Affected:

Date Picker, Date Range Picker (and the grid's date cell editor, which uses the date picker)

How Has This Been Tested?

New Destroy specs for both pickers render the picker inside an @if. For each of dropdown and dialog mode, they open the calendar, remove the picker, and assert that the calendar container is gone and that the detach warning wasn't logged. The new specs fail without the fix and pass with it.

The date picker unit tests mock the overlay service, so the mock now also has getOverlayById.

  • Unit tests
  • Manual testing
  • Automated e2e tests

Runs:

  • ng test igniteui-angular --no-watch --include 'projects/igniteui-angular/date-picker/**/*.spec.ts': 214 passed
  • grid-cell-editing.spec.ts and grid-row-editing.spec.ts: 62 passed
  • npm run lint:lib: no new errors or warnings

Test Configuration:

  • Angular version: 22.2.3
  • Browser(s): Chromium (Vitest browser mode via Playwright)
  • OS: Windows 11

Screenshots / Recordings

N/A: the only visible effect was a console warning.

Checklist:

  • All relevant labels have been applied to this PR
  • This PR includes unit tests covering all the new code (test guidelines)
  • This PR includes API docs for newly added methods/properties (api docs guidelines)
  • This PR includes feature/README.MD updates for the feature docs
  • This PR includes general feature table updates in the root README.MD
  • This PR includes CHANGELOG.MD updates for newly added functionality
  • This PR contains breaking changes
  • This PR includes ng update migrations for the breaking changes (migrations guidelines)
  • This PR includes behavioral changes and the feature specification has been updated with them
  • Accessibility (ARIA, keyboard navigation, focus management) has been verified

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the change preventing duplicate overlay detachment when open date pickers are destroyed.

No open issues 🎉

What changed in this PR

Fixes #17938 by preventing duplicate calendar overlay detachment when a date picker or date range picker is destroyed while open, including during grid date-cell editing.

Changes:

  • Guard both pickers’ destruction-time detach calls with getOverlayById and always clear _overlayId.
  • Add regression tests for destruction while open in dropdown and dialog modes.
  • Extend the date picker’s overlay mock with getOverlayById.
File Description
projects/​igniteui-angular/​date-picker/​src/​date-range-picker/​date-range-picker.component.ts Guard overlay detachment and clear the stored overlay ID.
projects/​igniteui-angular/​date-picker/​src/​date-range-picker/​date-range-picker.component.spec.ts Test destruction while open in both interaction modes.
projects/​igniteui-angular/​date-picker/​src/​date-picker/​date-picker.component.ts Guard overlay detachment and unconditionally clear the overlay ID.
projects/​igniteui-angular/​date-picker/​src/​date-picker/​date-picker.component.spec.ts Add destruction regression tests and update the overlay mock.

Review effort: Balanced

@ivanvpetrov
ivanvpetrov marked this pull request as ready for review November 10, 2026 13:44
@viktorkombov viktorkombov added 💥 status: in-test PRs currently being tested and removed ❌ status: awaiting-test PRs awaiting manual verification labels Nov 10, 2026
@viktorkombov

Copy link
Copy Markdown
Contributor

Please add a CHANGELOG entry under ## 22.3.0 → ### Bug Fixes, in the existing IgxDatePickerComponent and IgxDateRangePickerComponent groups.
FYI: the grid's advanced filtering dialog logs the same warning when the grid is destroyed with the dialog open. Logged separately as #17962.

@viktorkombov viktorkombov added ✅ status: verified Applies to PRs that have passed manual verification and removed 💥 status: in-test PRs currently being tested labels Nov 11, 2026
@ivanvpetrov

Copy link
Copy Markdown
Contributor Author

Please add a CHANGELOG entry under ## 22.3.0 → ### Bug Fixes, in the existing IgxDatePickerComponent and IgxDateRangePickerComponent groups. FYI: the grid's advanced filtering dialog logs the same warning when the grid is destroyed with the dialog open. Logged separately as #17962.

I've added a CHANGELOG entry. I'll also address the advanced filtering dialog in a separate PRs

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Date Picker] "igxOverlay.detach was called with wrong id" when a picker is destroyed with its calendar open

3 participants