Skip to content

Commit 6a6bc16

Browse files
crisbetotinayuangao
authored andcommitted
chore: fix connected overlay demo (#11325)
With 8735aa5 all demos had their style encapsulation enabled, however this ended up breaking the connected overlay demo because it has some styles that are targeting an overlay. These changes fix the styling and simplify the overlay setup.
1 parent bd9ba9c commit 6a6bc16

File tree

4 files changed

+18
-37
lines changed

4 files changed

+18
-37
lines changed

src/demo-app/connected-overlay/connected-overlay-demo.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,11 @@ <h2>Options</h2>
102102
</div>
103103

104104
<div style="height: 500px"></div>
105+
106+
<ng-template #overlay>
107+
<div class="demo-overlay">
108+
<div style="overflow: auto;">
109+
<ul><li *ngFor="let item of itemArray; index as i">{{itemText}} {{i}}</li></ul>
110+
</div>
111+
</div>
112+
</ng-template>

src/demo-app/connected-overlay/connected-overlay-demo.scss

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
}
1313
}
1414

15-
demo-overlay {
15+
.demo-overlay {
1616
display: block;
1717

1818
background: lightblue;
@@ -29,12 +29,3 @@ demo-overlay {
2929
align-items: center;
3030
padding: 10px;
3131
}
32-
33-
.cdk-overlay-connected-position-bounding-box.demo-show-box {
34-
background: orangered;
35-
opacity: 0.2;
36-
37-
.cdk-overlay-pane {
38-
opacity: 1;
39-
}
40-
}

src/demo-app/connected-overlay/connected-overlay-demo.ts

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import {
1414
OverlayRef,
1515
VerticalConnectionPos
1616
} from '@angular/cdk/overlay';
17-
import {ComponentPortal} from '@angular/cdk/portal';
18-
import {Component, ViewChild, ViewContainerRef} from '@angular/core';
17+
import {TemplatePortal} from '@angular/cdk/portal';
18+
import {Component, TemplateRef, ViewChild, ViewContainerRef} from '@angular/core';
1919

2020

2121
@Component({
@@ -26,6 +26,7 @@ import {Component, ViewChild, ViewContainerRef} from '@angular/core';
2626
})
2727
export class ConnectedOverlayDemo {
2828
@ViewChild(CdkOverlayOrigin) _overlayOrigin: CdkOverlayOrigin;
29+
@ViewChild('overlay') overlayTemplate: TemplateRef<any>;
2930

3031
originX: HorizontalConnectionPos = 'start';
3132
originY: VerticalConnectionPos = 'bottom';
@@ -37,6 +38,7 @@ export class ConnectedOverlayDemo {
3738
offsetX = 0;
3839
offsetY = 0;
3940
itemCount = 25;
41+
itemArray: any[] = [];
4042
itemText = 'Item with a long name';
4143
overlayRef: OverlayRef | null;
4244

@@ -82,11 +84,8 @@ export class ConnectedOverlayDemo {
8284
minHeight: 50
8385
});
8486

85-
const portal = new ComponentPortal(DemoOverlay, this.viewContainerRef);
86-
const componentRef = this.overlayRef.attach(portal);
87-
88-
componentRef.instance.items = Array(this.itemCount);
89-
componentRef.instance.text = this.itemText;
87+
this.itemArray = Array(this.itemCount);
88+
this.overlayRef.attach(new TemplatePortal(this.overlayTemplate, this.viewContainerRef));
9089
}
9190

9291
close() {
@@ -98,26 +97,11 @@ export class ConnectedOverlayDemo {
9897
}
9998

10099
toggleShowBoundingBox() {
101-
const box = document.querySelector('.cdk-overlay-connected-position-bounding-box');
100+
const box = document.querySelector<HTMLElement>('.cdk-overlay-connected-position-bounding-box');
102101

103102
if (box) {
104103
this.showBoundingBox = !this.showBoundingBox;
105-
box.classList.toggle('demo-show-box');
104+
box.style.background = this.showBoundingBox ? 'rgb(255, 69, 0, 0.2)' : '';
106105
}
107106
}
108107
}
109-
110-
111-
@Component({
112-
selector: 'demo-overlay',
113-
template: `
114-
<div style="overflow: auto;">
115-
<ul><li *ngFor="let item of items; index as i">{{text}} {{i}}</li></ul>
116-
</div>`,
117-
118-
})
119-
export class DemoOverlay {
120-
items: number[];
121-
text: string;
122-
}
123-

src/demo-app/demo-app/demo-module.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {ButtonDemo} from '../button/button-demo';
2424
import {CardDemo} from '../card/card-demo';
2525
import {CheckboxDemo, MatCheckboxDemoNestedChecklist} from '../checkbox/checkbox-demo';
2626
import {ChipsDemo} from '../chips/chips-demo';
27-
import {ConnectedOverlayDemo, DemoOverlay} from '../connected-overlay/connected-overlay-demo';
27+
import {ConnectedOverlayDemo} from '../connected-overlay/connected-overlay-demo';
2828
import {CustomHeader, DatepickerDemo} from '../datepicker/datepicker-demo';
2929
import {DemoMaterialModule} from '../demo-material-module';
3030
import {ContentElementDialog, DialogDemo, IFrameDialog, JazzDialog} from '../dialog/dialog-demo';
@@ -95,7 +95,6 @@ import {MaterialExampleModule} from '../example/example-module';
9595
CustomHeader,
9696
DatepickerDemo,
9797
DemoApp,
98-
DemoOverlay,
9998
DialogDemo,
10099
DrawerDemo,
101100
ExampleBottomSheet,
@@ -143,7 +142,6 @@ import {MaterialExampleModule} from '../example/example-module';
143142
ContentElementDialog,
144143
CustomHeader,
145144
DemoApp,
146-
DemoOverlay,
147145
ExampleBottomSheet,
148146
IFrameDialog,
149147
JazzDialog,

0 commit comments

Comments
 (0)