Skip to content

Commit

Permalink
fix(checkbox): disabled checkbox could be checked (#2001)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaishi authored Jan 4, 2023
1 parent 4270ae1 commit a69f4bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/checkbox/_example/group.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<t-checkbox-group v-model="value2" @change="onChange2">
<t-checkbox :checkAll="true" label="全选" />
<t-checkbox value="选项一">选项一</t-checkbox>
<t-checkbox label="选项二" value="选项二" />
<t-checkbox label="选项二" value="选项二" :disabled="true" />
<t-checkbox label="选项三" value="选项三" />
</t-checkbox-group>
</t-space>
Expand Down
13 changes: 8 additions & 5 deletions src/checkbox/group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,25 @@ export default mixins(classPrefixMixins).extend({
}
return '';
},
canCheckedCheckbox(): Array<CheckboxOptionObj> {
return this.optionList.filter((item) => item.disabled !== true);
},
intersectionLen(): number {
const values = this.optionList.map((item) => item.value);
const values = this.canCheckedCheckbox.map((item) => item.value);
if (this.value instanceof Array) {
const n = intersection(this.value, values);
return n.length;
}
return 0;
},
isCheckAll(): boolean {
if (this.value instanceof Array && this.value.length !== this.optionList.length - 1) {
if (this.value instanceof Array && this.value.length !== this.canCheckedCheckbox.length - 1) {
return false;
}
return this.intersectionLen === this.optionList.length - 1;
return this.intersectionLen === this.canCheckedCheckbox.length - 1;
},
indeterminate(): boolean {
return !this.isCheckAll && this.intersectionLen < this.optionList.length && this.intersectionLen !== 0;
return !this.isCheckAll && this.intersectionLen < this.canCheckedCheckbox.length && this.intersectionLen !== 0;
},
maxExceeded(): boolean {
return this.max !== undefined && this.value.length === this.max;
Expand Down Expand Up @@ -177,7 +180,7 @@ export default mixins(classPrefixMixins).extend({
const val = new Set<TdCheckboxProps['value']>();
for (let i = 0, len = this.optionList.length; i < len; i++) {
const item = this.optionList[i];
if (item.checkAll) continue;
if (item.checkAll || item.disabled) continue;
val.add(item.value);
if (this.maxExceeded) break;
}
Expand Down

0 comments on commit a69f4bb

Please sign in to comment.