forked from valor-software/ngx-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(modal): add method to change modal window class (valor-software#…
…4811) Fixes valor-software#2824 * fix(test): increase code coverage * Update modal-backdrop.component.spec.ts * feat(modal-backdrop): added tests to modal-backdrop component * Update modal-backdrop.component.spec.ts * Update modal-backdrop.component.spec.ts * Update modal-backdrop.component.spec.ts * Update modal-backdrop.component.spec.ts * Update modal-backdrop.component.spec.ts * fix(files): clean up
- Loading branch information
Showing
7 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
demo/src/app/components/+modal/demos/service-options/change-class/change-class.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<button type="button" class="btn btn-primary" (click)="openModal(template)">Create template modal</button> | ||
|
||
<ng-template #template> | ||
<div class="modal-header"> | ||
<h4 class="modal-title pull-left">Modal</h4> | ||
<button type="button" class="close pull-right" aria-label="Close" (click)="modalRef.hide()"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
<div class="modal-body"> | ||
This is a modal. | ||
</div> | ||
<button type="button" class="btn" (click)="setModalClass()">Change width</button> | ||
</ng-template> |
26 changes: 26 additions & 0 deletions
26
demo/src/app/components/+modal/demos/service-options/change-class/change-class.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Component, TemplateRef } from '@angular/core'; | ||
import { BsModalService } from 'ngx-bootstrap/modal'; | ||
import { BsModalRef } from 'ngx-bootstrap/modal/bs-modal-ref.service'; | ||
|
||
@Component({ | ||
selector: 'demo-modal-change-class', | ||
templateUrl: './change-class.html' | ||
}) | ||
export class DemoModalServiceChangeClassComponent { | ||
modalRef: BsModalRef; | ||
valueWidth = false; | ||
constructor(private modalService: BsModalService) {} | ||
|
||
openModal(template: TemplateRef<any>) { | ||
this.modalRef = this.modalService.show( | ||
template, | ||
Object.assign({}, { class: 'modal-sm' }) | ||
); | ||
} | ||
|
||
setModalClass() { | ||
this.valueWidth = !this.valueWidth; | ||
const modalWidth = this.valueWidth ? 'modal-lg' : 'modal-sm'; | ||
this.modalRef.setClass(modalWidth); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ModalBackdropComponent } from '../modal'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
describe('ModalBackdropComponent tests', () => { | ||
let fixture: ComponentFixture<ModalBackdropComponent>; | ||
let component: ModalBackdropComponent; | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ModalBackdropComponent] | ||
}); | ||
fixture = TestBed.createComponent(ModalBackdropComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should get and set isAnimated correctly', () => { | ||
component.isAnimated = true; | ||
expect(component.isAnimated).toBeTruthy(); | ||
}); | ||
|
||
it('isShown() tests', () => { | ||
component.isShown = true; | ||
fixture.detectChanges(); | ||
let modalClass = component.element.nativeElement.classList.contains('in'); | ||
expect(modalClass).toBeTruthy(); | ||
component.isShown = false; | ||
fixture.detectChanges(); | ||
modalClass = component.element.nativeElement.classList.contains('in'); | ||
expect(modalClass).toBeFalsy(); | ||
}); | ||
}); |