Skip to content

Commit 3ffe173

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

File tree

7 files changed

+25
-10
lines changed

7 files changed

+25
-10
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: 1 addition & 0 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)

0 commit comments

Comments
 (0)