diff --git a/demo-app/views/AppForm.vue b/demo-app/views/AppForm.vue index ca7caae5..a0c2d3ee 100644 --- a/demo-app/views/AppForm.vue +++ b/demo-app/views/AppForm.vue @@ -1,12 +1,14 @@ - + + +

ChecboxSet :

+ + Sélectionné(s) : {{ selectedCheckboxes }} + +

Checbox seule :

+ + Sélectionné : {{ selectedCheckbox }} diff --git a/docs/docs-demo/DsfrCheckboxSetV7Demo.vue b/docs/docs-demo/DsfrCheckboxSetV7Demo.vue new file mode 100644 index 00000000..dc7bb54d --- /dev/null +++ b/docs/docs-demo/DsfrCheckboxSetV7Demo.vue @@ -0,0 +1,42 @@ + + + diff --git a/docs/guide/migrations.md b/docs/guide/migrations.md index e1024677..7d9d442c 100644 --- a/docs/guide/migrations.md +++ b/docs/guide/migrations.md @@ -1,10 +1,19 @@ # Migrations -## Migration vers 6.x (depuis 4.x ou 5.x) +## Migration vers 7.x (depuis 4.x, 5.x ou 6.x) -Dans cette version majeure, il y a plusieurs sujets à traiter lorsque vous migrerez : +Avant la v7, le tableau `modelValue` de [`DsfrCheckboxSet`](/composants/DsfrCheckboxSet) était un tableau de `string` avec les valeurs des propriétés de l’attribut `name` de chaque case à cocher. + +Ce n’était ni une API idéale, ni le comportement attendu en Vue natif ou en HTML/JS natif. + +::: code-group + + + + +<<< ../docs-demo/DsfrCheckboxSetV7Demo.vue [Code de la démo] +::: -1. Les icônes 2. Les onglets 3. Les accordéons @@ -250,3 +259,7 @@ export default defineNuxtConfig({ ], }) ``` + + diff --git a/src/components/DsfrCheckbox/DsfrCheckbox.types.ts b/src/components/DsfrCheckbox/DsfrCheckbox.types.ts index cdba0503..aa4b34f6 100644 --- a/src/components/DsfrCheckbox/DsfrCheckbox.types.ts +++ b/src/components/DsfrCheckbox/DsfrCheckbox.types.ts @@ -1,10 +1,12 @@ import type { InputHTMLAttributes } from 'vue' -export type DsfrCheckboxProps = { +export type DsfrCheckboxProps = { id?: string name: string required?: boolean - modelValue?: boolean + value: T + checked?: boolean + modelValue: Array small?: boolean inline?: boolean label?: string @@ -13,7 +15,7 @@ export type DsfrCheckboxProps = { hint?: string } -export type DsfrCheckboxSetProps = { +export type DsfrCheckboxSetProps = { titleId?: string disabled?: boolean inline?: boolean @@ -23,6 +25,6 @@ export type DsfrCheckboxSetProps = { validMessage?: string legend?: string options?: (DsfrCheckboxProps & InputHTMLAttributes)[] - modelValue?: string[] + modelValue?: T[] ariaInvalid?: boolean } diff --git a/src/components/DsfrCheckbox/DsfrCheckbox.vue b/src/components/DsfrCheckbox/DsfrCheckbox.vue index 90209bae..b8007739 100644 --- a/src/components/DsfrCheckbox/DsfrCheckbox.vue +++ b/src/components/DsfrCheckbox/DsfrCheckbox.vue @@ -18,16 +18,10 @@ const props = withDefaults(defineProps(), { label: '', }) -const emit = defineEmits<{ (event: 'update:modelValue', value: boolean): void }>() - const message = computed(() => props.errorMessage || props.validMessage) const additionalMessageClass = computed(() => props.errorMessage ? 'fr-error-text' : 'fr-valid-text') - -const emitNewValue = ($event: InputEvent) => { - // @ts-expect-error This is a checkbox input event, so `checked` property is present - emit('update:modelValue', $event.target.checked) -} +const modelValue = defineModel()