Skip to content

Commit c63d735

Browse files
authored
refactor(cdk/overlay): revert internal workaround (angular#32374)
Reverts a workaround now that it isn't necessary anymore.
1 parent 744c396 commit c63d735

File tree

3 files changed

+26
-45
lines changed

3 files changed

+26
-45
lines changed

src/cdk/overlay/overlay-ref.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ export type ImmutableObject<T> = {
3232
readonly [P in keyof T]: T[P];
3333
};
3434

35+
/** Checks if a value is an element. */
36+
export function isElement(value: any): value is Element {
37+
return value && (value as Element).nodeType === 1;
38+
}
39+
3540
/**
3641
* Reference to an overlay that has been created with the Overlay service.
3742
* Used to manipulate or dispose of said overlay.
@@ -409,14 +414,10 @@ export class OverlayRef implements PortalOutlet {
409414
? this._positionStrategy?.getPopoverInsertionPoint?.()
410415
: null;
411416

412-
if (customInsertionPoint) {
413-
if (customInsertionPoint instanceof Element) {
414-
customInsertionPoint.after(this._host);
415-
} else {
416-
if (customInsertionPoint.type === 'parent') {
417-
customInsertionPoint.element?.appendChild(this._host);
418-
}
419-
}
417+
if (isElement(customInsertionPoint)) {
418+
customInsertionPoint.after(this._host);
419+
} else if (customInsertionPoint?.type === 'parent') {
420+
customInsertionPoint.element.appendChild(this._host);
420421
} else {
421422
this._previousHostParent?.appendChild(this._host);
422423
}

src/cdk/overlay/overlay.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {OverlayKeyboardDispatcher} from './dispatchers/overlay-keyboard-dispatch
2828
import {OverlayOutsideClickDispatcher} from './dispatchers/overlay-outside-click-dispatcher';
2929
import {OverlayConfig} from './overlay-config';
3030
import {_CdkOverlayStyleLoader, OverlayContainer} from './overlay-container';
31-
import {OverlayRef} from './overlay-ref';
31+
import {isElement, OverlayRef} from './overlay-ref';
3232
import {OverlayPositionBuilder} from './position/overlay-position-builder';
3333
import {ScrollStrategyOptions} from './scroll/index';
3434

@@ -89,19 +89,14 @@ export function createOverlayRef(injector: Injector, config?: OverlayConfig): Ov
8989
? overlayConfig.positionStrategy?.getPopoverInsertionPoint?.()
9090
: null;
9191

92-
overlayContainer.getContainerElement().appendChild(host);
93-
94-
// Note: it's redundant to pass the `host` through the container element above if
95-
// it's going to end up at the custom insertion point anyways. We need to do it,
96-
// because some internal clients depend on the host passing through the container first.
97-
if (customInsertionPoint) {
98-
if (customInsertionPoint instanceof Element) {
99-
customInsertionPoint.after(host);
100-
} else {
101-
if (customInsertionPoint.type === 'parent') {
102-
customInsertionPoint.element?.appendChild(host);
103-
}
104-
}
92+
if (isElement(customInsertionPoint)) {
93+
customInsertionPoint.after(host);
94+
} else if (customInsertionPoint?.type === 'parent') {
95+
customInsertionPoint.element.appendChild(host);
96+
} else {
97+
// Note: leave the container for last so that we fall
98+
// back to it for unsupported/newly-added values.
99+
overlayContainer.getContainerElement().appendChild(host);
105100
}
106101

107102
return new OverlayRef(

src/cdk/overlay/position/flexible-connected-position-strategy.ts

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {isElementScrolledOutsideView, isElementClippedByScrolling} from './scrol
2222
import {coerceCssPixelValue, coerceArray} from '../../coercion';
2323
import {Platform} from '../../platform';
2424
import {OverlayContainer} from '../overlay-container';
25-
import {OverlayRef} from '../overlay-ref';
25+
import {isElement, OverlayRef} from '../overlay-ref';
2626

2727
// TODO: refactor clipping detection into a separate thing (part of scrolling module)
2828
// TODO: doesn't handle both flexible width and height when it has to scroll along both axis.
@@ -537,32 +537,17 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
537537
getPopoverInsertionPoint(): Element | null | {type: 'parent'; element: Element} {
538538
if (this._popoverLocation === 'global') {
539539
return null;
540+
} else if (this._popoverLocation !== 'inline') {
541+
return this._popoverLocation;
540542
}
541543

542-
let hostElement: Element | null = null;
543-
544-
if (this._popoverLocation === 'inline') {
545-
if (this._origin instanceof ElementRef) {
546-
hostElement = this._origin.nativeElement;
547-
} else if (this._origin instanceof Element) {
548-
hostElement = this._origin;
549-
}
544+
if (this._origin instanceof ElementRef) {
545+
return this._origin.nativeElement;
546+
} else if (isElement(this._origin)) {
547+
return this._origin;
550548
} else {
551-
// this._popoverLocation is {type: 'parent', element: Element}
552-
hostElement = this._popoverLocation.element;
553-
}
554-
555-
// If the location is 'inline', we're inserting as a sibling.
556-
if (this._popoverLocation === 'inline') {
557-
return hostElement;
558-
}
559-
560-
// Otherwise we're inserting as a child.
561-
if (hostElement) {
562-
return {type: 'parent', element: hostElement};
549+
return null;
563550
}
564-
565-
return null;
566551
}
567552

568553
/**

0 commit comments

Comments
 (0)