Skip to content

Commit

Permalink
feat(modal): add modalDialogClass to modal-dialog div (#3826)
Browse files Browse the repository at this point in the history
Co-authored-by: Michaela Tesařová <michaela.tesarova@ext.csas.cz>
  • Loading branch information
MisuleT and Michaela Tesařová committed Mar 23, 2021
1 parent 3992021 commit 37c0331
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/modal/modal-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ export interface NgbModalOptions {
*/
windowClass?: string;

/**
* A custom class to append to the modal dialog.
*/
modalDialogClass?: string;

/**
* A custom class to append to the modal backdrop.
*
Expand Down Expand Up @@ -122,6 +127,7 @@ export class NgbModalConfig implements Required<NgbModalOptions> {
scrollable: boolean;
size: 'sm' | 'lg' | 'xl' | string;
windowClass: string;
modalDialogClass: string;
backdropClass: string;

private _animation: boolean;
Expand Down
9 changes: 9 additions & 0 deletions src/modal/modal-window.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,14 @@ describe('ngb-modal-dialog', () => {
expect(fixture.nativeElement.getAttribute('role')).toBe('dialog');
expect(dialogEl.getAttribute('role')).toBe('document');
});

it('should render modal dialog with a specified class', () => {
fixture.componentInstance.modalDialogClass = 'custom-dialog-class';
fixture.detectChanges();

const dialogEl: Element = fixture.nativeElement.querySelector('.modal-dialog');
expect(dialogEl).toHaveCssClass('modal-dialog');
expect(dialogEl).toHaveCssClass('custom-dialog-class');
});
});
});
3 changes: 2 additions & 1 deletion src/modal/modal-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {reflow} from '../util/util';
},
template: `
<div #dialog [class]="'modal-dialog' + (size ? ' modal-' + size : '') + (centered ? ' modal-dialog-centered' : '') +
(scrollable ? ' modal-dialog-scrollable' : '')" role="document">
(scrollable ? ' modal-dialog-scrollable' : '') + (modalDialogClass ? ' ' + modalDialogClass : '')" role="document">
<div class="modal-content"><ng-content></ng-content></div>
</div>
`,
Expand All @@ -59,6 +59,7 @@ export class NgbModalWindow implements OnInit,
@Input() scrollable: string;
@Input() size: string;
@Input() windowClass: string;
@Input() modalDialogClass: string;

@Output('dismiss') dismissEvent = new EventEmitter();

Expand Down

0 comments on commit 37c0331

Please sign in to comment.