diff --git a/packages/checkbox/src/checkbox-button.vue b/packages/checkbox/src/checkbox-button.vue index 61fc1d617d0..446a071f291 100644 --- a/packages/checkbox/src/checkbox-button.vue +++ b/packages/checkbox/src/checkbox-button.vue @@ -35,7 +35,7 @@ @focus="focus = true" @blur="focus = false"> - {{label}} @@ -150,9 +150,17 @@ return this._checkboxGroup.checkboxGroupSize || this._elFormItemSize || (this.$ELEMENT || {}).size; }, + /* used to make the isDisabled judgment under max/min props */ + isLimitDisabled() { + const { max, min } = this._checkboxGroup; + return !!(max || min) && + (this.model.length >= max && !this.isChecked) || + (this.model.length <= min && this.isChecked); + }, + isDisabled() { return this._checkboxGroup - ? this._checkboxGroup.disabled || this.disabled || (this.elForm || {}).disabled + ? this._checkboxGroup.disabled || this.disabled || (this.elForm || {}).disabled || this.isLimitDisabled : this.disabled || (this.elForm || {}).disabled; } }, diff --git a/packages/checkbox/src/checkbox.vue b/packages/checkbox/src/checkbox.vue index f30f4b2d66c..6e882a1cc87 100644 --- a/packages/checkbox/src/checkbox.vue +++ b/packages/checkbox/src/checkbox.vue @@ -136,9 +136,17 @@ return this._checkboxGroup ? this._checkboxGroup.value : this.value; }, + /* used to make the isDisabled judgment under max/min props */ + isLimitDisabled() { + const { max, min } = this._checkboxGroup; + return !!(max || min) && + (this.model.length >= max && !this.isChecked) || + (this.model.length <= min && this.isChecked); + }, + isDisabled() { return this.isGroup - ? this._checkboxGroup.disabled || this.disabled || (this.elForm || {}).disabled + ? this._checkboxGroup.disabled || this.disabled || (this.elForm || {}).disabled || this.isLimitDisabled : this.disabled || (this.elForm || {}).disabled; }, diff --git a/test/unit/specs/checkbox.spec.js b/test/unit/specs/checkbox.spec.js index 4e1bc99480c..eefd49b2079 100644 --- a/test/unit/specs/checkbox.spec.js +++ b/test/unit/specs/checkbox.spec.js @@ -147,6 +147,7 @@ describe('Checkbox', () => { } }, true); expect(vm.checkList.length === 1).to.be.true; + expect(vm.$refs.a.isDisabled).to.be.true; vm.$refs.a.$el.click(); vm.$nextTick(() => { expect(vm.checkList.indexOf('a') !== -1).to.be.true; @@ -158,6 +159,8 @@ describe('Checkbox', () => { vm.$nextTick(() => { expect(vm.checkList.indexOf('c') !== -1).to.be.false; expect(vm.checkList.indexOf('d') !== -1).to.be.false; + expect(vm.$refs.c.isDisabled).to.be.true; + expect(vm.$refs.d.isDisabled).to.be.true; done(); }); });