Skip to content

Commit

Permalink
Checkbox: Using the max attribute can limit the number of items that …
Browse files Browse the repository at this point in the history
…can be checked (#14742)
  • Loading branch information
masongzhi committed May 16, 2019
1 parent 16a6059 commit 878c1c1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/checkbox/src/checkbox-button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
@focus="focus = true"
@blur="focus = false">

<span class="el-checkbox-button__inner"
<span class="el-checkbox-button__inner"
v-if="$slots.default || label"
:style="isChecked ? activeStyle : null">
<slot>{{label}}</slot>
Expand Down Expand Up @@ -152,7 +152,7 @@
isDisabled() {
return this._checkboxGroup
? this._checkboxGroup.disabled || this.disabled || (this.elForm || {}).disabled
? this._checkboxGroup.disabled || this.disabled || (this.elForm || {}).disabled || (this.model.length >= this._checkboxGroup.max && !this.isChecked) || (this.model.length <= this._checkboxGroup.min && this.isChecked)
: this.disabled || (this.elForm || {}).disabled;
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/checkbox/src/checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
isDisabled() {
return this.isGroup
? this._checkboxGroup.disabled || this.disabled || (this.elForm || {}).disabled
? this._checkboxGroup.disabled || this.disabled || (this.elForm || {}).disabled || (this.model.length >= this._checkboxGroup.max && !this.isChecked) || (this.model.length <= this._checkboxGroup.min && this.isChecked)
: this.disabled || (this.elForm || {}).disabled;
},
Expand Down
3 changes: 3 additions & 0 deletions test/unit/specs/checkbox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
});
});
Expand Down

0 comments on commit 878c1c1

Please sign in to comment.