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

feat(module:modal): support set nzOkDisabled and nzCancelDisabled #2856

Merged
merged 7 commits into from
Feb 1, 2019
2 changes: 2 additions & 0 deletions components/modal/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ The dialog is currently divided into 2 modes, `normal mode` and `confirm box mod
| nzClosable | Whether a close (x) button is visible on top right of the modal dialog or not. <i>Invalid value in confirm box mode (default will be hidden)</i> | `boolean` | `true` |
| nzOkLoading | Whether to apply loading visual effect for OK button or not | `boolean` | `false` |
| nzCancelLoading | Whether to apply loading visual effect for Cancel button or not | `boolean` | `false` |
| nzOkDisabled | Whether to disable Ok button or not | `boolean` | `false` |
| nzCancelDisabled | Whether to disable Cancel button or not | `boolean` | `false` |
| nzFooter | Footer content, set as footer=null when you don't need default buttons. <i>1. Only valid in normal mode.<br>2. You can customize the buttons to the maximum extent by passing a `ModalButtonOptions` configuration (see the case or the instructions below).</i> | string<br>TemplateRef<br>ModalButtonOptions | OK and Cancel buttons |
| nzGetContainer | The mount node for Modal | HTMLElement / () => HTMLElement| A default container |
| nzKeyboard | Whether support press esc to close | `boolean` | `true` |
Expand Down
2 changes: 2 additions & 0 deletions components/modal/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ title: Modal
| nzClosable | 是否显示右上角的关闭按钮。<i>确认框模式下该值无效(默认会被隐藏)</i> | `boolean` | `true` |
| nzOkLoading | 确定按钮 loading | `boolean` | `false` |
| nzCancelLoading | 取消按钮 loading | `boolean` | `false` |
| nzOkDisabled | 是否禁用确定按钮 | `boolean` | `false` |
| nzCancelDisabled | 是否禁用取消按钮 | `boolean` | `false` |
| nzFooter | 底部内容。<i>1. 仅在普通模式下有效。<br>2. 可通过传入 ModalButtonOptions 来最大程度自定义按钮(详见案例或下方说明)。<br>3. 当不需要底部时,可以设为 null</i> | string<br>TemplateRef<br>ModalButtonOptions | 默认的确定取消按钮 |
| nzGetContainer | 指定 Modal 挂载的 HTML 节点 | HTMLElement<br>() => HTMLElement| 默认容器 |
| nzKeyboard | 是否支持键盘esc关闭 | `boolean` | `true` |
Expand Down
4 changes: 2 additions & 2 deletions components/modal/nz-modal.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@
>{{ button.label }}</button>
</ng-container>
<ng-container *ngSwitchDefault>
<button *ngIf="nzCancelText!==null" nz-button (click)="onClickOkCancel('cancel')" [nzLoading]="nzCancelLoading">
<button *ngIf="nzCancelText!==null" nz-button (click)="onClickOkCancel('cancel')" [nzLoading]="nzCancelLoading" [disabled]="nzCancelDisabled">
{{ cancelText }}
</button>
<button *ngIf="nzOkText!==null" nz-button [nzType]="nzOkType" (click)="onClickOkCancel('ok')" [nzLoading]="nzOkLoading">
<button *ngIf="nzOkText!==null" nz-button [nzType]="nzOkType" (click)="onClickOkCancel('ok')" [nzLoading]="nzOkLoading" [disabled]="nzOkDisabled">
{{ okText }}
</button>
</ng-container>
Expand Down
3 changes: 2 additions & 1 deletion components/modal/nz-modal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ export class NzModalComponent<T = any, R = any> extends NzModalRef<T, R> impleme
get cancelText(): string {
return this.nzCancelText || this.locale.cancelText;
}

@Input() @InputBoolean() nzOkDisabled: boolean = false;
@Input() @InputBoolean() nzCancelDisabled: boolean = false;
@Input() @InputBoolean() nzCancelLoading: boolean = false;
@Input() @Output() readonly nzOnCancel: EventEmitter<T> | OnClickCallback<T> = new EventEmitter<T>();
@ViewChild('modalContainer') modalContainer: ElementRef;
Expand Down
4 changes: 4 additions & 0 deletions components/modal/nz-modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ describe('modal testing (legacy)', () => {
expect(isButtonLoading(getButtonCancel(modalElement))).not.toBeFalsy();
expect(modalElement.querySelector('.ant-modal-close')).toBeFalsy();
expect(modalElement.querySelector('.ant-modal-mask')).toBeFalsy();
expect(getButtonOk(modalElement).disabled).toBeFalsy();
expect(getButtonCancel(modalElement).disabled).toBeFalsy();

// click ok button
getButtonOk(modalElement).click();
Expand Down Expand Up @@ -690,6 +692,8 @@ class TestBasicServiceComponent {
nzOkText: 'custom ok',
nzOkType: 'success',
nzOkLoading: false,
nzOkDisabled: false,
nzCancelDisabled: false,
nzOnOk: () => { console.log('click ok'); return false; },
nzCancelText: 'custom cancel',
nzCancelLoading: true,
Expand Down
2 changes: 2 additions & 0 deletions components/modal/nz-modal.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export interface ModalOptions<T = any, R = any> { // tslint:disable-line:no-any
nzOkText?: string;
nzOkType?: string;
nzOkLoading?: boolean;
nzOkDisabled?: boolean;
nzCancelDisabled?: boolean;
nzOnOk?: EventEmitter<T> | OnClickCallback<T>; // Mixed using ng's Input/Output (Should care of "this" when using OnClickCallback)
nzCancelText?: string;
nzCancelLoading?: boolean;
Expand Down