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

fix(checkbox): disabled checkbox could be checked #2001

Merged
merged 1 commit into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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