Files
heroui-vue/apps/docs/demos/checkbox-group-indeterminate.vue
T
2026-10-22 09:15:27 +08:00

58 lines
1.5 KiB
Vue

<script setup lang="ts">
import {
CheckboxGroup,
CheckboxContent,
CheckboxControl,
CheckboxIndicator,
Checkbox,
} from "@heroui-vue/components";
import { ref } from "vue";
const selected = ref(["coding"]);
const allOptions = ["coding", "design", "writing"];
</script>
<template>
<div>
<Checkbox
:is-indeterminate="
selected.length > 0 && selected.length < allOptions.length
"
:checked="selected.length === allOptions.length"
name="select-all"
@update:checked="selected = $event ? [...allOptions] : []"
>
<CheckboxContent>
<CheckboxControl><CheckboxIndicator /></CheckboxControl>
全选
</CheckboxContent>
</Checkbox>
<div class="ms-6 flex flex-col gap-2">
<CheckboxGroup v-model="selected">
<Checkbox value="coding">
<CheckboxContent>
<CheckboxControl>
<CheckboxIndicator />
</CheckboxControl>
编程
</CheckboxContent>
</Checkbox>
<Checkbox value="design">
<CheckboxContent>
<CheckboxControl>
<CheckboxIndicator />
</CheckboxControl>
设计
</CheckboxContent>
</Checkbox>
<Checkbox value="writing">
<CheckboxContent>
<CheckboxControl>
<CheckboxIndicator />
</CheckboxControl>
写作
</CheckboxContent>
</Checkbox>
</CheckboxGroup>
</div>
</div>
</template>