From 986aab09abdd5e4833344100eb71533a44f04a33 Mon Sep 17 00:00:00 2001 From: wuwen Date: Thu, 4 Jan 2018 16:40:10 +0800 Subject: [PATCH] fix(module:readio): fix disabled still clickable in button style --- .../radio/nz-radio-button.component.ts | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/components/radio/nz-radio-button.component.ts b/src/components/radio/nz-radio-button.component.ts index 6cec0700518..8dcf98543d1 100644 --- a/src/components/radio/nz-radio-button.component.ts +++ b/src/components/radio/nz-radio-button.component.ts @@ -1,6 +1,6 @@ import { Component, - HostBinding, + HostBinding, HostListener, Input, OnInit, ViewEncapsulation, @@ -51,4 +51,40 @@ export class NzRadioButtonComponent extends NzRadioComponent implements OnInit { get nzChecked(): boolean { return this._radioButtonChecked; } + + @HostListener('click', [ '$event' ]) + onClick(e: MouseEvent): void { + e.preventDefault(); + if (!this._radioButtonDisabled) { + if (this._nzRadioGroup) { + this._radioButtonChecked = true; + this.setClassMap(); + this._nzRadioGroup.selectRadio(this); + } else { + this.updateValue(!this._radioButtonChecked); + } + } + } + + setClassMap(): void { + this._classMap = { + [this._prefixCls] : true, + [`${this._prefixCls}-checked`] : this._radioButtonChecked, + [`${this._prefixCls}-disabled`]: this._radioButtonDisabled + }; + } + + updateValue(value: boolean): void { + if (value === this._radioButtonChecked) { + return; + } + this.onChange(value); + this._radioButtonChecked = value; + this.setClassMap(); + } + + writeValue(value: boolean): void { + this._radioButtonChecked = value; + this.setClassMap(); + } }