Skip to content

Commit 01f81a2

Browse files
committed
refactor(cdk/overlay): enable popover by default
Enables popovers for all overlays by default.
1 parent 969a9ab commit 01f81a2

File tree

8 files changed

+38
-22
lines changed

8 files changed

+38
-22
lines changed

src/cdk/overlay/_index.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ $backdrop-animation-timing-function: cubic-bezier(0.25, 0.8, 0.25, 1) !default;
195195
position: fixed;
196196
pointer-events: none;
197197
white-space: normal;
198-
line-height: normal;
198+
color: inherit;
199199
text-decoration: none;
200200

201201
// These are important so the overlay can be measured before it's fully inserted.
@@ -206,13 +206,18 @@ $backdrop-animation-timing-function: cubic-bezier(0.25, 0.8, 0.25, 1) !default;
206206
// with `align-self` can break the positioning (see #29809).
207207
inset: auto;
208208

209+
// Some older versions of Chrome won't render the popover properly without these.
210+
top: 0;
211+
left: 0;
212+
209213
// For the time being we're using our `.cdk-overlay-backdrop` element instead of the native one.
210214
&::backdrop {
211215
display: none;
212216
}
213217

214218
.cdk-overlay-backdrop {
215219
position: fixed;
220+
z-index: auto;
216221
}
217222
}
218223
}

src/cdk/overlay/overlay-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class OverlayConfig {
6565
* Whether the overlay should be rendered as a native popover element,
6666
* rather than placing it inside of the overlay container.
6767
*/
68-
usePopover?: boolean = false;
68+
usePopover?: boolean;
6969

7070
constructor(config?: OverlayConfig) {
7171
if (config) {

src/cdk/overlay/overlay-directives.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
253253

254254
/** Whether the connected overlay should be rendered inside a popover element or the overlay container. */
255255
@Input({alias: 'cdkConnectedOverlayUsePopover'})
256-
usePopover: FlexibleOverlayPopoverLocation | null = null;
256+
usePopover: FlexibleOverlayPopoverLocation | null = 'global';
257257

258258
/** Whether the overlay should match the trigger's width. */
259259
@Input({alias: 'cdkConnectedOverlayMatchWidth', transform: booleanAttribute})

src/cdk/overlay/overlay-ref.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,12 @@ export class OverlayRef implements PortalOutlet {
417417
}
418418

419419
if (this._config.usePopover) {
420-
this._host.showPopover();
420+
// We need the try/catch because the browser will throw if the
421+
// host or any of the parents are outside the DOM. Also note
422+
// the string access which is there for compatibility with Closure.
423+
try {
424+
this._host['showPopover']();
425+
} catch {}
421426
}
422427
}
423428

src/cdk/overlay/overlay.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ describe('Overlay', () => {
141141
expect(overlayContainerElement.textContent).toBe('');
142142
});
143143

144-
it('should ensure that the most-recently-attached overlay is on top', () => {
145-
let pizzaOverlayRef = createOverlayRef(injector);
146-
let cakeOverlayRef = createOverlayRef(injector);
144+
it('should ensure that the most-recently-attached overlay is on top when popovers are disabled', () => {
145+
let pizzaOverlayRef = createOverlayRef(injector, {usePopover: false});
146+
let cakeOverlayRef = createOverlayRef(injector, {usePopover: false});
147147

148148
pizzaOverlayRef.attach(componentPortal);
149149
cakeOverlayRef.attach(templatePortal);
@@ -850,7 +850,7 @@ describe('Overlay', () => {
850850
});
851851

852852
it('should insert the backdrop before the overlay host in the DOM order', () => {
853-
const overlayRef = createOverlayRef(injector, config);
853+
const overlayRef = createOverlayRef(injector, {...config, usePopover: false});
854854

855855
overlayRef.attach(componentPortal);
856856
viewContainerFixture.detectChanges();

src/cdk/overlay/overlay.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,13 @@ export function createOverlayRef(injector: Injector, config?: OverlayConfig): Ov
5252
injector.get(RendererFactory2).createRenderer(null, null);
5353

5454
const overlayConfig = new OverlayConfig(config);
55-
5655
overlayConfig.direction = overlayConfig.direction || directionality.value;
57-
overlayConfig.usePopover = !!overlayConfig?.usePopover && 'showPopover' in doc.body;
56+
57+
if (!('showPopover' in doc.body)) {
58+
overlayConfig.usePopover = false;
59+
} else {
60+
overlayConfig.usePopover = config?.usePopover ?? true;
61+
}
5862

5963
const pane = doc.createElement('div');
6064
const host = doc.createElement('div');

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ describe('FlexibleConnectedPositionStrategy', () => {
140140
overlayContainer.getContainerElement().style.top = '-100px';
141141

142142
attachOverlay({
143+
usePopover: false,
143144
positionStrategy: createFlexibleConnectedPositionStrategy(injector, originElement)
144145
.withFlexibleDimensions(false)
145146
.withPush(false)
@@ -2642,7 +2643,7 @@ describe('FlexibleConnectedPositionStrategy', () => {
26422643
attachOverlay({positionStrategy});
26432644

26442645
expect(overlayRef.hostElement.style.left).toBeTruthy();
2645-
expect(overlayRef.hostElement.style.right).toBeFalsy();
2646+
expect(overlayRef.hostElement.style.right).toBe('auto');
26462647
});
26472648

26482649
it('should use `right` when positioning an element at the end', () => {
@@ -2658,7 +2659,7 @@ describe('FlexibleConnectedPositionStrategy', () => {
26582659
attachOverlay({positionStrategy});
26592660

26602661
expect(overlayRef.hostElement.style.right).toBeTruthy();
2661-
expect(overlayRef.hostElement.style.left).toBeFalsy();
2662+
expect(overlayRef.hostElement.style.left).toBe('auto');
26622663
});
26632664
});
26642665

@@ -2679,7 +2680,7 @@ describe('FlexibleConnectedPositionStrategy', () => {
26792680
});
26802681

26812682
expect(overlayRef.hostElement.style.right).toBeTruthy();
2682-
expect(overlayRef.hostElement.style.left).toBeFalsy();
2683+
expect(overlayRef.hostElement.style.left).toBe('auto');
26832684
});
26842685

26852686
it('should use `left` when positioning an element at the end', () => {
@@ -2695,7 +2696,7 @@ describe('FlexibleConnectedPositionStrategy', () => {
26952696
attachOverlay({positionStrategy, direction: 'rtl'});
26962697

26972698
expect(overlayRef.hostElement.style.left).toBeTruthy();
2698-
expect(overlayRef.hostElement.style.right).toBeFalsy();
2699+
expect(overlayRef.hostElement.style.right).toBe('auto');
26992700
});
27002701
});
27012702

@@ -2713,7 +2714,7 @@ describe('FlexibleConnectedPositionStrategy', () => {
27132714
attachOverlay({positionStrategy});
27142715

27152716
expect(overlayRef.hostElement.style.top).toBeTruthy();
2716-
expect(overlayRef.hostElement.style.bottom).toBeFalsy();
2717+
expect(overlayRef.hostElement.style.bottom).toBe('auto');
27172718
});
27182719

27192720
it('should use `bottom` when positioning at element along the bottom', () => {
@@ -2729,7 +2730,7 @@ describe('FlexibleConnectedPositionStrategy', () => {
27292730
attachOverlay({positionStrategy});
27302731

27312732
expect(overlayRef.hostElement.style.bottom).toBeTruthy();
2732-
expect(overlayRef.hostElement.style.top).toBeFalsy();
2733+
expect(overlayRef.hostElement.style.top).toBe('auto');
27332734
});
27342735
});
27352736
});

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -923,18 +923,19 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
923923

924924
if (this._hasExactPosition()) {
925925
styles.top = styles.left = '0';
926-
styles.bottom = styles.right = styles.maxHeight = styles.maxWidth = '';
926+
styles.bottom = styles.right = 'auto';
927+
styles.maxHeight = styles.maxWidth = '';
927928
styles.width = styles.height = '100%';
928929
} else {
929930
const maxHeight = this._overlayRef.getConfig().maxHeight;
930931
const maxWidth = this._overlayRef.getConfig().maxWidth;
931932

932-
styles.height = coerceCssPixelValue(boundingBoxRect.height);
933-
styles.top = coerceCssPixelValue(boundingBoxRect.top);
934-
styles.bottom = coerceCssPixelValue(boundingBoxRect.bottom);
935933
styles.width = coerceCssPixelValue(boundingBoxRect.width);
936-
styles.left = coerceCssPixelValue(boundingBoxRect.left);
937-
styles.right = coerceCssPixelValue(boundingBoxRect.right);
934+
styles.height = coerceCssPixelValue(boundingBoxRect.height);
935+
styles.top = coerceCssPixelValue(boundingBoxRect.top) || 'auto';
936+
styles.bottom = coerceCssPixelValue(boundingBoxRect.bottom) || 'auto';
937+
styles.left = coerceCssPixelValue(boundingBoxRect.left) || 'auto';
938+
styles.right = coerceCssPixelValue(boundingBoxRect.right) || 'auto';
938939

939940
// Push the pane content towards the proper direction.
940941
if (position.overlayX === 'center') {

0 commit comments

Comments
 (0)