feat : ajout d'un sélecteur "Tout cocher" dans le composant SelectCheckbox

This commit is contained in:
2026-03-19 17:30:52 +01:00
parent 187ef52865
commit 9d9b9c9dc4
3 changed files with 140 additions and 0 deletions

View File

@@ -143,6 +143,21 @@
: 'border-m-primary'
]"
>
<li
v-if="displaySelectAll"
class="border-b border-m-muted/30 px-3 py-2"
@mousedown.prevent
>
<Checkbox
:model-value="allSelected"
:label="selectAllLabel"
:disabled="disabled"
group-class="!mt-0"
label-class="option-checkbox w-full cursor-pointer font-semibold"
tabindex="-1"
@update:model-value="toggleAll"
/>
</li>
<li
v-for="(opt, index) in normalizedOptions"
:id="optionId(index)"
@@ -212,6 +227,8 @@ const props = withDefaults(defineProps<{
textLabel?: string
rounded?: string
displayTag?: boolean
displaySelectAll?: boolean
selectAllLabel?: string
disabled?: boolean
}>(), {
options: () => [],
@@ -227,6 +244,8 @@ const props = withDefaults(defineProps<{
textLabel: 'text-sm',
rounded: 'rounded-md',
displayTag: false,
displaySelectAll: false,
selectAllLabel: 'Tout sélectionner',
disabled: false,
})
@@ -330,6 +349,19 @@ function toggle() {
open()
}
const allSelected = computed(() =>
normalizedOptions.value.length > 0
&& normalizedOptions.value.every(opt => props.modelValue.includes(opt.value)),
)
function toggleAll() {
if (allSelected.value) {
emit('update:modelValue', [])
} else {
emit('update:modelValue', normalizedOptions.value.map(opt => opt.value))
}
}
function isChecked(value: string | number) {
return props.modelValue.includes(value)
}