Skip to content

Commit 3ef0346

Browse files
author
Evan Qualls
committed
feat(modal): Add container property to ModalOptions
Updated documentation pages Updated test case for ModalOptions.container property
1 parent e0a42da commit 3ef0346

File tree

7 files changed

+43
-8
lines changed

7 files changed

+43
-8
lines changed

apps/ngx-bootstrap-docs/src/ng-api-doc.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2746,6 +2746,11 @@ export const ngdoc: any = {
27462746
"type": "string",
27472747
"description": "<p>Css class for opened modal</p>\n"
27482748
},
2749+
{
2750+
"name": "container",
2751+
"type": "string | ElementRef",
2752+
"description": "<p>The CSS Selector or ElementRef for where the modal window will be injected into the page.</p>\n"
2753+
},
27492754
{
27502755
"name": "closeInterceptor",
27512756
"type": "CloseInterceptorFn",

libs/common-docs/src/lib/demo-section-components/demo-examples-section/examples.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ <h3 *ngIf="item.title" [attr.id]="item.anchor" class="d-flex justify-content-bet
1919
</p>
2020
</h3>
2121
<p *ngIf="item.description" [innerHTML]="item.description"></p>
22-
<ng-sample-box [ts]="item?.component?.default" [html]="item?.html?.default" [style]="item.style ">
22+
<ng-sample-box [ts]="item?.component?.default" [html]="item?.html?.default" [style]="item.style?.default">
2323
<ng-container *ngComponentOutlet="item.outlet"></ng-container>
2424
</ng-sample-box>
2525
</div>

libs/common-docs/src/lib/models/components-examples.model.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface ComponentExample {
66
description?: string;
77
component?: SourceCodeModel;
88
html?: SourceCodeModel;
9-
style?: string;
9+
style?: SourceCodeModel;
1010
css?: string;
1111
outlet?: any; // ToDo: Component<T>
1212
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.profit {
2+
color: green;
3+
font-weight: 700;
4+
}

libs/doc-pages/modal/src/lib/demos/service-component/service-component.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ export class DemoModalServiceFromComponent {
1212

1313
openModalWithComponent() {
1414
const initialState: ModalOptions = {
15+
container: 'bs-demo',
1516
initialState: {
1617
list: [
1718
'Open a modal with component',
1819
'Pass your data',
1920
'Do something else',
20-
'...'
21+
'...',
22+
'Push button to find out!'
2123
],
2224
title: 'Modal with component'
2325
}
@@ -32,6 +34,7 @@ export class DemoModalServiceFromComponent {
3234
@Component({
3335
// eslint-disable-next-line @angular-eslint/component-selector
3436
selector: 'modal-content',
37+
styleUrls: ['./service-component.css'],
3538
template: `
3639
<div class="modal-header">
3740
<h4 class="modal-title pull-left">{{title}}</h4>
@@ -41,23 +44,27 @@ export class DemoModalServiceFromComponent {
4144
</div>
4245
<div class="modal-body">
4346
<ul *ngIf="list.length">
44-
<li *ngFor="let item of list">{{item}}</li>
47+
<li *ngFor="let item of list" [ngClass]="{ 'profit' : item === 'PROFIT!!!'}">{{item}}</li>
4548
</ul>
4649
</div>
4750
<div class="modal-footer">
51+
<button *ngIf="!profitBtnPressed" type="button" class="btn btn-default" (click)="showProfit()">Find Out</button>
4852
<button type="button" class="btn btn-default" (click)="bsModalRef.hide()">{{closeBtnName}}</button>
4953
</div>
5054
`
5155
})
5256

53-
export class ModalContentComponent implements OnInit {
57+
export class ModalContentComponent {
5458
title?: string;
59+
profitBtnPressed: boolean = false;
5560
closeBtnName?: string;
5661
list: any[] = [];
5762

5863
constructor(public bsModalRef: BsModalRef) {}
5964

60-
ngOnInit() {
61-
this.list.push('PROFIT!!!');
65+
showProfit() {
66+
this.profitBtnPressed = true;
67+
this.list[this.list.length - 1] = 'PROFIT!!!';
6268
}
69+
6370
}

libs/doc-pages/modal/src/lib/modal-section.list.ts

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export const demoComponentContent: ContentSection[] = [
6060
anchor: 'service-component',
6161
component: require('!!raw-loader!./demos/service-component/service-component.ts'),
6262
html: require('!!raw-loader!./demos/service-component/service-component.html'),
63+
style: require('!!raw-loader!./demos/service-component/service-component.css'),
6364
description: `<p>Creating a modal with component just as easy as it is with template. Just pass your component
6465
in <code>.show()</code> method as in example, and don't forget to include your component to
6566
<code>entryComponents</code> of your <code>NgModule</code><br> If you passed a component

src/modal/testing/modal.service.spec.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import { pairwise, tap } from 'rxjs/operators';
44

55
import { BsModalService, ModalModule } from '../index';
66

7-
@Component({ template: '<div>Dummy Component</div>' })
7+
@Component({
8+
selector: 'dummy-component',
9+
template: '<div>Dummy Component</div>' })
810
class DummyComponent {
911
// eslint-disable-next-line @typescript-eslint/no-empty-function,@typescript-eslint/no-unused-vars
1012
constructor(modalService: BsModalService) { }
@@ -130,4 +132,20 @@ describe('Modal service', () => {
130132
jest.runAllTimers();
131133
expect(onHiddenSpy).toHaveBeenCalledWith({ id });
132134
});
135+
136+
it('should render in <body> element by default', done => {
137+
modalService.onShown.subscribe((data) => {
138+
expect(document.querySelector('dummy-component modal-container')).toBeDefined();
139+
done();
140+
})
141+
modalService.show(TestModalComponent);
142+
})
143+
144+
it('should render in the container selector provided', done => {
145+
modalService.onShown.subscribe((data) => {
146+
expect(document.querySelector('dummy-component modal-container')).toBeDefined();
147+
done();
148+
})
149+
modalService.show(TestModalComponent, { container: 'dummy-component'});
150+
})
133151
});

0 commit comments

Comments
 (0)