Skip to content

fix(material/datepicker): resolve server-side rendering error #26742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/material/datepicker/calendar-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Platform} from '@angular/cdk/platform';
import {
ChangeDetectionStrategy,
Component,
Expand All @@ -19,6 +20,7 @@ import {
SimpleChanges,
OnDestroy,
AfterViewChecked,
inject,
} from '@angular/core';
import {take} from 'rxjs/operators';

Expand Down Expand Up @@ -71,6 +73,8 @@ let calendarBodyId = 1;
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MatCalendarBody<D = any> implements OnChanges, OnDestroy, AfterViewChecked {
private _platform = inject(Platform);

/**
* Used to skip the next focus event when rendering the preview range.
* We need a flag like this, because some browsers fire focus events asynchronously.
Expand Down Expand Up @@ -177,8 +181,11 @@ export class MatCalendarBody<D = any> implements OnChanges, OnDestroy, AfterView
element.addEventListener('blur', this._leaveHandler, true);
element.addEventListener('mousedown', this._mousedownHandler);
element.addEventListener('touchstart', this._mousedownHandler);
window.addEventListener('mouseup', this._mouseupHandler);
window.addEventListener('touchend', this._touchendHandler);

if (this._platform.isBrowser) {
window.addEventListener('mouseup', this._mouseupHandler);
window.addEventListener('touchend', this._touchendHandler);
}
});
}

Expand Down Expand Up @@ -232,8 +239,11 @@ export class MatCalendarBody<D = any> implements OnChanges, OnDestroy, AfterView
element.removeEventListener('blur', this._leaveHandler, true);
element.removeEventListener('mousedown', this._mousedownHandler);
element.removeEventListener('touchstart', this._mousedownHandler);
window.removeEventListener('mouseup', this._mouseupHandler);
window.removeEventListener('touchend', this._touchendHandler);

if (this._platform.isBrowser) {
window.removeEventListener('mouseup', this._mouseupHandler);
window.removeEventListener('touchend', this._touchendHandler);
}
}

/** Returns whether a cell is active. */
Expand Down