Skip to content

Commit e2ea66a

Browse files
committed
feat(cdk/overlay): Add option to inline overlay
1 parent 8b47c8f commit e2ea66a

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/cdk/overlay/overlay.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,21 @@ export function createOverlayRef(injector: Injector, config?: OverlayConfig): Ov
4848
const appRef = injector.get(ApplicationRef);
4949
const directionality = injector.get(Directionality);
5050

51+
// Create the overlay pane and a parent which will then be attached to the document.
5152
const host = doc.createElement('div');
5253
const pane = doc.createElement('div');
53-
5454
pane.id = idGenerator.getId('cdk-overlay-');
5555
pane.classList.add('cdk-overlay-pane');
5656
host.appendChild(pane);
57-
overlayContainer.getContainerElement().appendChild(host);
57+
58+
// Insert after the specified element, or onto the global overlay container.
59+
if (config?.insertOverlayAfter) {
60+
const element = config.insertOverlayAfter.nativeElement;
61+
element.after(host);
62+
element.parentElement.style.position = 'relative';
63+
} else {
64+
overlayContainer.getContainerElement().appendChild(host);
65+
}
5866

5967
const portalOutlet = new DomPortalOutlet(pane, appRef, injector);
6068
const overlayConfig = new OverlayConfig(config);

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,14 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
579579
overlayStartY = pos.overlayY == 'top' ? 0 : -overlayRect.height;
580580
}
581581

582+
// Adjust the overly position when it is placed inline relative to its parent.
583+
const insertOverlayAfter = this._overlayRef.getConfig().insertOverlayAfter;
584+
if (insertOverlayAfter) {
585+
const rect = insertOverlayAfter!.nativeElement.getBoundingClientRect();
586+
overlayStartX -= rect.left;
587+
overlayStartY -= rect.top;
588+
}
589+
582590
// The (x, y) coordinates of the overlay.
583591
return {
584592
x: originPoint.x + overlayStartX,
@@ -881,7 +889,14 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
881889
if (this._hasExactPosition()) {
882890
styles.top = styles.left = '0';
883891
styles.bottom = styles.right = styles.maxHeight = styles.maxWidth = '';
884-
styles.width = styles.height = '100%';
892+
893+
if (this._overlayRef.getConfig().insertOverlayAfter) {
894+
styles.width = coerceCssPixelValue(boundingBoxRect.width);
895+
styles.height = coerceCssPixelValue(boundingBoxRect.height);
896+
} else {
897+
// TODO(andreyd): can most likley remove this for common case
898+
styles.width = styles.height = '100%';
899+
}
885900
} else {
886901
const maxHeight = this._overlayRef.getConfig().maxHeight;
887902
const maxWidth = this._overlayRef.getConfig().maxWidth;

0 commit comments

Comments
 (0)