Skip to content

Commit e0a42da

Browse files
authored
Add files via upload
feat(modal): Add container property to ModalOptions These changes will allow developers to optionally place render modals within the application context, allowing components injected via BsModalService to use ViewEncapsulation and support change detection. * Added container<string | ElementRef> property to ModalOptions. * Updated modalConfigDefaults with "container: 'body' " to prevent breaking changes/behavior * Updated BsModalService and Modal-Directive so that the container element is no longer hard-coded to 'body' but rather config.container
1 parent 4440667 commit e0a42da

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/modal/bs-modal.service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export class BsModalService {
110110
if (isBackdropEnabled && isBackdropInDOM) {
111111
this._backdropLoader
112112
.attach(ModalBackdropComponent)
113-
.to('body')
113+
.to(this.config.container)
114114
.show({ isAnimated: this.config.animated });
115115
this.backdropRef = this._backdropLoader._componentRef;
116116
}
@@ -140,7 +140,7 @@ export class BsModalService {
140140
.provide({ provide: ModalOptions, useValue: this.config })
141141
.provide({ provide: BsModalRef, useValue: bsModalRef })
142142
.attach(ModalContainerComponent)
143-
.to('body');
143+
.to(this.config.container);
144144
bsModalRef.hide = () => this.hide(bsModalRef.id);
145145
bsModalRef.setClass = (newClass: string) => {
146146
if (modalContainerRef.instance) {

src/modal/modal-options.class.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable, StaticProvider, InjectionToken } from '@angular/core';
1+
import { ElementRef, Injectable, StaticProvider, InjectionToken } from '@angular/core';
22
import { ClassName, CloseInterceptorFn, DismissReasons, Selector, TransitionDurations } from './models';
33

44
@Injectable({providedIn: 'platform'})
@@ -30,6 +30,10 @@ export class ModalOptions<T = Record<string, unknown>> {
3030
* Css class for opened modal
3131
*/
3232
class?: string;
33+
/**
34+
* CSS selector or ElementRef to which the modal is appended
35+
*/
36+
container?: string | ElementRef;
3337
/**
3438
* Toggle animation
3539
*/
@@ -63,6 +67,7 @@ export const modalConfigDefaults: ModalOptions = {
6367
show: false,
6468
ignoreBackdropClick: false,
6569
class: '',
70+
container: 'body',
6671
animated: true,
6772
initialState: {},
6873
closeInterceptor: void 0

src/modal/modal.directive.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ export class ModalDirective implements OnDestroy, OnInit {
337337
this.removeBackdrop();
338338
this._backdrop
339339
.attach(ModalBackdropComponent)
340-
.to('body')
340+
.to(this._config.container)
341341
.show({ isAnimated: this._config.animated });
342342
this.backdrop = this._backdrop._componentRef;
343343

0 commit comments

Comments
 (0)