Skip to content
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

fix(multiple): move afterRender calls back outside zone #28981

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/cdk/overlay/overlay-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@
*/

import {Direction, Directionality} from '@angular/cdk/bidi';
import {coerceArray, coerceCssPixelValue} from '@angular/cdk/coercion';
import {ComponentPortal, Portal, PortalOutlet, TemplatePortal} from '@angular/cdk/portal';
import {Location} from '@angular/common';
import {
AfterRenderRef,
ComponentRef,
EmbeddedViewRef,
EnvironmentInjector,
NgZone,
afterNextRender,
afterRender,
untracked,
AfterRenderRef,
} from '@angular/core';
import {Location} from '@angular/common';
import {Observable, Subject, merge, SubscriptionLike, Subscription} from 'rxjs';
import {Observable, Subject, Subscription, SubscriptionLike, merge} from 'rxjs';
import {takeUntil} from 'rxjs/operators';
import {OverlayKeyboardDispatcher} from './dispatchers/overlay-keyboard-dispatcher';
import {OverlayOutsideClickDispatcher} from './dispatchers/overlay-outside-click-dispatcher';
import {OverlayConfig} from './overlay-config';
import {coerceCssPixelValue, coerceArray} from '@angular/cdk/coercion';
import {PositionStrategy} from './position/position-strategy';
import {ScrollStrategy} from './scroll';

Expand Down Expand Up @@ -495,10 +495,11 @@ export class OverlayRef implements PortalOutlet {
// Run this outside the Angular zone because there's nothing that Angular cares about.
// If it were to run inside the Angular zone, every test that used Overlay would have to be
// either async or fakeAsync.
this._backdropTimeout = this._ngZone.runOutsideAngular(() =>
setTimeout(() => {
this._disposeBackdrop(backdropToDetach);
}, 500),
this._backdropTimeout = this._ngZone.runOutsideAngular(
() =>
setTimeout(() => {
this._disposeBackdrop(backdropToDetach);
}, 500) as any,
);
}

Expand Down
38 changes: 20 additions & 18 deletions src/material/datepicker/calendar-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@
*/

import {Platform, normalizePassiveListenerOptions} from '@angular/cdk/platform';
import {NgClass} from '@angular/common';
import {
AfterViewChecked,
ChangeDetectionStrategy,
Component,
ElementRef,
EventEmitter,
Injector,
Input,
Output,
ViewEncapsulation,
NgZone,
OnChanges,
SimpleChanges,
OnDestroy,
AfterViewChecked,
inject,
Output,
SimpleChanges,
ViewEncapsulation,
afterNextRender,
Injector,
inject,
} from '@angular/core';
import {NgClass} from '@angular/common';

/** Extra CSS classes that can be associated with a calendar cell. */
export type MatCalendarCellCssClasses = string | string[] | Set<string> | {[key: string]: any};
Expand Down Expand Up @@ -314,18 +314,20 @@ export class MatCalendarBody<D = any> implements OnChanges, OnDestroy, AfterView
_focusActiveCell(movePreview = true) {
afterNextRender(
() => {
setTimeout(() => {
const activeCell: HTMLElement | null = this._elementRef.nativeElement.querySelector(
'.mat-calendar-body-active',
);

if (activeCell) {
if (!movePreview) {
this._skipNextFocus = true;
this._ngZone.runOutsideAngular(() => {
setTimeout(() => {
const activeCell: HTMLElement | null = this._elementRef.nativeElement.querySelector(
'.mat-calendar-body-active',
);

if (activeCell) {
if (!movePreview) {
this._skipNextFocus = true;
}

activeCell.focus();
}

activeCell.focus();
}
});
});
},
{injector: this._injector},
Expand Down