Skip to content

Commit 29e2c46

Browse files
authored
fix(material-experimental/column-resize): add null checks for overlay (#32259)
Fixes some null pointer errors that show up in the logs for some internal apps.
1 parent 969a9ab commit 29e2c46

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

src/cdk-experimental/column-resize/resizable.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -182,28 +182,28 @@ export abstract class Resizable<HandleComponent extends ResizeOverlayHandle>
182182

183183
private _listenForRowHoverEvents(): void {
184184
const element = this.elementRef.nativeElement!;
185-
const takeUntilDestroyed = takeUntil<boolean>(this.destroyed);
186185

187186
this.eventDispatcher
188187
.resizeOverlayVisibleForHeaderRow(_closest(element, HEADER_ROW_SELECTOR)!)
189-
.pipe(takeUntilDestroyed)
188+
.pipe(takeUntil(this.destroyed))
190189
.subscribe(hoveringRow => {
190+
if (this._isDestroyed) {
191+
return;
192+
}
193+
191194
if (hoveringRow) {
192195
const tooBigToResize =
193196
this.maxWidthPxInternal < Number.MAX_SAFE_INTEGER &&
194197
element.offsetWidth > this.maxWidthPxInternal;
195198
element.classList.toggle(RESIZE_DISABLED_CLASS, tooBigToResize);
196199

197200
if (!tooBigToResize) {
198-
if (!this.overlayRef) {
199-
this.overlayRef = this._createOverlayForHandle();
200-
}
201-
201+
this.overlayRef ??= this._createOverlayForHandle();
202202
this._showHandleOverlay();
203203
}
204-
} else if (this.overlayRef) {
204+
} else {
205205
// todo - can't detach during an active resize - need to work that out
206-
this.overlayRef.detach();
206+
this.overlayRef?.detach();
207207
}
208208
});
209209
}
@@ -258,7 +258,7 @@ export abstract class Resizable<HandleComponent extends ResizeOverlayHandle>
258258
private _cleanUpAfterResize(columnSize: ColumnSizeAction): void {
259259
this.elementRef.nativeElement!.classList.remove(OVERLAY_ACTIVE_CLASS);
260260

261-
if (this.overlayRef && this.overlayRef.hasAttached()) {
261+
if (this.overlayRef?.hasAttached()) {
262262
this._updateOverlayHandleHeight();
263263
this.overlayRef.updatePosition();
264264

@@ -293,18 +293,20 @@ export abstract class Resizable<HandleComponent extends ResizeOverlayHandle>
293293
}
294294

295295
private _showHandleOverlay(): void {
296-
this._updateOverlayHandleHeight();
297-
this.overlayRef!.attach(this._createHandlePortal());
296+
if (!this._isDestroyed) {
297+
this._updateOverlayHandleHeight();
298+
this.overlayRef?.attach(this._createHandlePortal());
298299

299-
// Needed to ensure that all of the lifecycle hooks inside the overlay run immediately.
300-
this.changeDetectorRef.markForCheck();
300+
// Needed to ensure that all of the lifecycle hooks inside the overlay run immediately.
301+
this.changeDetectorRef.markForCheck();
302+
}
301303
}
302304

303305
private _updateOverlayHandleHeight() {
304306
runInInjectionContext(this.injector, () => {
305307
afterNextRender({
306308
write: () => {
307-
this.overlayRef!.updateSize({height: this.elementRef.nativeElement!.offsetHeight});
309+
this.overlayRef?.updateSize({height: this.elementRef.nativeElement!.offsetHeight});
308310
},
309311
});
310312
});

src/dev-app/theme-m3.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@use '@angular/material' as mat;
2+
@use '@angular/material-experimental' as matx;
23

34
// Plus imports for other components in your app.
45

@@ -38,7 +39,7 @@ html {
3839
@include mat.system-level-colors($light-theme);
3940
@include mat.system-level-typography($light-theme);
4041
// TODO(mmalerba): Support M3 for experimental components.
41-
// @include matx.column-resize-theme($light-theme);
42+
@include matx.column-resize-theme($light-theme);
4243
// @include matx.popover-edit-theme($light-theme);
4344
}
4445

src/material-experimental/column-resize/_column-resize-theme.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
@use 'sass:map';
33

44
@mixin color($theme) {
5-
$resizable-hover-divider: mat.get-theme-color($theme, primary, 600);
6-
$resizable-active-divider: mat.get-theme-color($theme, primary, 600);
5+
$resizable-hover-divider: mat.get-theme-color($theme, primary, 60);
6+
$resizable-active-divider: mat.get-theme-color($theme, primary, 60);
77

88
// TODO: these styles don't really belong in the `color` part of the theme.
99
// We should figure out a better place for them.

0 commit comments

Comments
 (0)