Skip to content

Commit

Permalink
fix(module:modal): buttons cannot disable when confirm mode (#3707)
Browse files Browse the repository at this point in the history
* fix(module:modal): buttons cannot disable when confirm mode

close #3679

* fix: fix build
  • Loading branch information
hsuanxyz authored and vthinkxie committed Jul 15, 2019
1 parent c11ca9b commit 3847250
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
14 changes: 12 additions & 2 deletions components/modal/nz-modal.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,20 @@
</div>
</div>
<div class="ant-modal-confirm-btns">
<button nz-button *ngIf="nzCancelText!==null" (click)="onClickOkCancel('cancel')" [nzLoading]="nzCancelLoading">
<button *ngIf="nzCancelText!==null"
nz-button
(click)="onClickOkCancel('cancel')"
[nzLoading]="nzCancelLoading"
[disabled]="nzCancelDisabled">
{{ cancelText }}
</button>
<button *ngIf="nzOkText!==null" #autoFocusButtonOk nz-button [nzType]="nzOkType" (click)="onClickOkCancel('ok')" [nzLoading]="nzOkLoading">
<button #autoFocusButtonOk
*ngIf="nzOkText!==null"
nz-button
(click)="onClickOkCancel('ok')"
[nzType]="nzOkType"
[nzLoading]="nzOkLoading"
[disabled]="nzOkDisabled">
{{ okText }}
</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion components/modal/nz-modal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class NzModalComponent<T = any, R = any> extends NzModalRef<T, R>
@Input() nzBodyStyle: object;
@Input() nzOkText: string | null;
@Input() nzCancelText: string | null;
@Input() nzOkType = 'primary';
@Input() nzOkType: string = 'primary';
@Input() nzIconType: string = 'question-circle'; // Confirm Modal ONLY
@Input() nzModalType: ModalType = 'default';

Expand Down
18 changes: 18 additions & 0 deletions components/modal/nz-modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,17 @@ describe('modal testing (legacy)', () => {
ids.forEach(id => expectModalDestroyed(id, false));
}));

it('should disable buttons', fakeAsync(() => {
const modalRef = instance.createDisabledModal();
fixture.detectChanges();
flush();
fixture.detectChanges();
const buttons = modalRef.getElement().querySelectorAll('.ant-modal-confirm-btns button') as NodeListOf<
HTMLButtonElement
>;
buttons.forEach(button => expect(button.disabled).toBe(true));
}));

it('should render content with component', fakeAsync(() => {
const modalRef = instance.createCustomContentWithComponent();
const modalElement = modalRef.getElement();
Expand Down Expand Up @@ -931,6 +942,13 @@ export class TestConfirmModalComponent {
nzContent: TestConfirmCustomComponent
});
}

createDisabledModal(): NzModalRef {
return this.modalService.confirm({
nzCancelDisabled: true,
nzOkDisabled: true
});
}
}

@Component({
Expand Down

0 comments on commit 3847250

Please sign in to comment.