Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
fix(Checkbox): update model value when indeterminate changes (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
tewshi authored Mar 26, 2024
1 parent 6abeb5f commit ee4cb79
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
31 changes: 17 additions & 14 deletions src/components/forms/checkbox/Checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ const { size, value, errorMessages, successMessages, indeterminate } = toRefs(pr
const el = ref<HTMLInputElement | null>(null);
function input(target: EventTarget | null) {
if (!target)
return;
const { checked } = target as HTMLInputElement;
if (checked)
emit('update:indeterminate', false);
emit('input', checked);
}
const modelValue = computed({
get: () => get(value),
set: (checked: boolean) => {
if (checked)
emit('update:indeterminate', false);
emit('input', checked);
},
});
const iconSize: ComputedRef<number> = computed(() => {
const sizeVal = get(size);
Expand All @@ -75,10 +73,15 @@ const { hasError, hasSuccess } = useFormTextDetail(
successMessages,
);
watch(value, (val) => {
watch(indeterminate, (val) => {
const input = get(el);
if (input && input.checked !== val)
input.checked = val;
if (input) {
input.checked = !val;
if (val)
input.value = 'off';
else
input.value = 'on';
}
});
</script>

Expand All @@ -99,11 +102,11 @@ watch(value, (val) => {
>
<input
ref="el"
v-model="modelValue"
:class="css.input"
:disabled="disabled"
type="checkbox"
v-bind="getNonRootAttrs(attrs)"
@input="input($event.target)"
v-on="
// eslint-disable-next-line vue/no-deprecated-dollar-listeners-api
objectOmit($listeners, ['input', 'click'])
Expand Down
3 changes: 0 additions & 3 deletions src/components/tables/DataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1036,14 +1036,11 @@ onMounted(() => {
<TableHead
v-if="stickyHeader"
:loading="loading"
:indeterminate="indeterminate"
:capitalize-headers="!cols"
:colspan="colspan"
:column-attr="columnAttr"
:columns="columns"
:dense="dense"
:disable-check-all="!filtered?.length"
:is-all-selected="isAllSelected"
:no-data="noData"
:selectable="!!selectedData"
:sort-data="sortData"
Expand Down

0 comments on commit ee4cb79

Please sign in to comment.