Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added modal container as a configuration option #872

Merged
merged 7 commits into from
Jun 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ export class BackdropExamplesComponent {

openCustomBackdrop(modal): void {
this.modalService.open(modal, {
container: document.activeElement as HTMLElement,
backdropClass: 'modal-custom-overlay-example',
backdropClickCloseable: false,
maxWidth: '400px',
data: 'This modal has a custom backdrop! Classes applied to the backdrop' +
' must be in your global styles file. You may also need to override some properties using !important.'
' do not have to be in your global styles file.'
});
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Component, Input } from '@angular/core';
import { ModalService } from '../../../../../../../library/src/lib/modal/modal-service/modal.service';
import { Component } from '@angular/core';
import { ModalRef } from '../../../../../../../library/src/lib/modal/modal-utils/modal-ref';

@Component({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Input, ViewChild } from '@angular/core';
import { Component } from '@angular/core';
import { ModalService } from '../../../../../../../library/src/lib/modal/modal-service/modal.service';
import { ModalInModalSecondComponent } from './modal-in-modal-second.component';
import { ModalRef } from '../../../../../../../library/src/lib/modal/modal-utils/modal-ref';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ModalService } from '../../../../../../../library/src/lib/modal/modal-s
styles: ['.action-button {margin-left: 12px;}']
})
export class ModalOpenTemplateExampleComponent {

confirmationReason: string;

constructor(private modalService: ModalService) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<header>Modal</header>
<description>The modal is used as a container to be displayed in response to a action. It is commonly used to collect
simple information
with a short form, to get confirmation or display contextual information that does not require a page.
<description>
The modal is used as a container to be displayed in response to an action. It is commonly used to collect
simple information with a short form, to get confirmation or display contextual information
that does not require a page.
</description>
<import module="ModalModule" path="fundamental-ngx"></import>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { Component } from '@angular/core';

@Component({
selector: 'app-modal-docs-header',
templateUrl: './modal-docs-header.component.html',
styleUrls: ['./modal-docs-header.component.scss']
})
export class ModalDocsHeaderComponent implements OnInit {

constructor() { }

ngOnInit() {
}

}
export class ModalDocsHeaderComponent {}
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ <h2>Stacked Modals</h2>

<h2>Backdrop Configuration</h2>
<description>
The modal backdrop can be styled, disabled or even customized at will. Classes being applied to the backdrop must be
in the global styles file.
The modal backdrop can be styled, disabled or even customized at will. Classes being applied
to the element do not have to be in your global styles.
</description>
<component-example [name]="'ex6'">
<fd-backdrop-examples></fd-backdrop-examples>
Expand Down
6 changes: 5 additions & 1 deletion library/src/lib/modal/modal-service/modal.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ export class ModalService {

// Render container
const containerEl = (containerRef.hostView as EmbeddedViewRef<any>).rootNodes[0] as HTMLElement;
document.body.appendChild(containerEl);
if (modalConfig.container !== 'body') {
modalConfig.container.appendChild(containerEl);
} else {
document.body.appendChild(containerEl);
}

// Render backdrop
if (modalConfig.hasBackdrop) {
Expand Down
3 changes: 3 additions & 0 deletions library/src/lib/modal/modal-utils/modal-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export class ModalConfig {
/** Whether the modal should be focus trapped. */
focusTrapped?: boolean = true;

/** The container that the modal is appended to. By default, it is appended to the body. */
container?: HTMLElement | 'body' = 'body';

/** Data to pass along to the content through the ModalRef. */
data?: any;
}