Skip to content

Commit bbc6559

Browse files
committed
feat(cdk/overlay): add overlay changes
1 parent 45079a0 commit bbc6559

File tree

6 files changed

+22
-11
lines changed

6 files changed

+22
-11
lines changed

goldens/cdk/overlay/index.api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
284284
// (undocumented)
285285
detach(): void;
286286
dispose(): void;
287-
getPopoverInsertionPoint(): Element | null | {parent: Element};
287+
getPopoverInsertionPoint(): Element | null | {type: 'parent', element: Element};
288288
_origin: FlexibleConnectedPositionStrategyOrigin;
289289
positionChanges: Observable<ConnectedOverlayPositionChange>;
290290
get positions(): ConnectionPositionPair[];
@@ -536,7 +536,7 @@ export interface PositionStrategy {
536536
attach(overlayRef: OverlayRef): void;
537537
detach?(): void;
538538
dispose(): void;
539-
getPopoverInsertionPoint?(): Element | null | {parent: Element};
539+
getPopoverInsertionPoint?(): Element | null | {type: 'parent', element: Element};
540540
}
541541

542542
// @public

src/cdk/overlay/overlay-ref.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,9 @@ export class OverlayRef implements PortalOutlet {
413413
if (customInsertionPoint instanceof Element) {
414414
customInsertionPoint.after(this._host);
415415
} else {
416-
customInsertionPoint.parent?.appendChild(this._host);
416+
if (customInsertionPoint.type === 'parent') {
417+
customInsertionPoint.element?.appendChild(this._host);
418+
}
417419
}
418420
} else {
419421
this._previousHostParent?.appendChild(this._host);

src/cdk/overlay/overlay.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ export function createOverlayRef(injector: Injector, config?: OverlayConfig): Ov
9898
if (customInsertionPoint instanceof Element) {
9999
customInsertionPoint.after(host);
100100
} else {
101-
customInsertionPoint.parent.appendChild(host);
101+
if (customInsertionPoint.type === 'parent') {
102+
customInsertionPoint.element?.appendChild(host);
103+
}
102104
}
103105
}
104106

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3024,7 +3024,7 @@ describe('FlexibleConnectedPositionStrategy', () => {
30243024
return;
30253025
}
30263026

3027-
positionStrategy.withPopoverLocation({parent: customHostElement});
3027+
positionStrategy.withPopoverLocation({type: 'parent', element: customHostElement});
30283028
attachOverlay({positionStrategy, usePopover: true});
30293029

30303030
expect(containerElement.contains(overlayRef.hostElement)).toBe(false);
@@ -3037,7 +3037,7 @@ describe('FlexibleConnectedPositionStrategy', () => {
30373037
return;
30383038
}
30393039

3040-
positionStrategy.withPopoverLocation({parent: originElement});
3040+
positionStrategy.withPopoverLocation({type: 'parent', element: originElement});
30413041
attachOverlay({positionStrategy, usePopover: true});
30423042

30433043
expect(containerElement.contains(overlayRef.hostElement)).toBe(false);

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export type FlexibleConnectedPositionStrategyOrigin =
4646
type Dimensions = Omit<DOMRect, 'x' | 'y' | 'toJSON'>;
4747

4848
/** Possible point to attach a popover to. */
49-
export type PopoverInsertionPoint = Element | {parent: Element} | null;
49+
export type PopoverInsertionPoint = Element | {type: 'parent'; element: Element} | null;
5050

5151
/**
5252
* Creates a flexible position strategy.
@@ -70,7 +70,7 @@ export function createFlexibleConnectedPositionStrategy(
7070
export type FlexibleOverlayPopoverLocation =
7171
| 'global'
7272
| 'inline'
73-
| {parent: FlexibleConnectedPositionStrategyOrigin};
73+
| {type: 'parent'; element: FlexibleConnectedPositionStrategyOrigin};
7474

7575
/**
7676
* A strategy for positioning overlays. Using this strategy, an overlay is given an
@@ -528,6 +528,8 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
528528
* @param location Configures the location in the DOM. Supports the following values:
529529
* - `global` - The default which inserts the overlay inside the overlay container.
530530
* - `inline` - Inserts the overlay next to the trigger.
531+
* - {type: 'parent', element: element} - Inserts the overlay to a child of a custom parent
532+
* element.
531533
*/
532534
withPopoverLocation(location: FlexibleOverlayPopoverLocation): this {
533535
this._popoverLocation = location;
@@ -543,7 +545,12 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
543545
const origin =
544546
this._popoverLocation === 'inline'
545547
? this._origin
546-
: (this._popoverLocation as {parent: FlexibleConnectedPositionStrategyOrigin}).parent;
548+
: (
549+
this._popoverLocation as {
550+
type: 'parent';
551+
element: FlexibleConnectedPositionStrategyOrigin;
552+
}
553+
).element;
547554
let element: Element | null = null;
548555

549556
if (origin instanceof ElementRef) {
@@ -559,7 +566,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
559566

560567
// Otherwise we're inserting as a child.
561568
if (element) {
562-
return {parent: element};
569+
return {type: 'parent', element: element};
563570
}
564571

565572
return null;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ export interface PositionStrategy {
2626
* Gets the element in the DOM after which to insert
2727
* the overlay when it is rendered out as a popover.
2828
*/
29-
getPopoverInsertionPoint?(): Element | null | {parent: Element};
29+
getPopoverInsertionPoint?(): Element | null | {type: 'parent'; element: Element};
3030
}

0 commit comments

Comments
 (0)