From 82fae732887dcd060846087975bf2dff986ff7f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanislas=20Ormi=C3=A8res?= Date: Sun, 15 Sep 2024 22:24:24 +0200 Subject: [PATCH] =?UTF-8?q?feat(DsfrCheckboxSet)!:=20am=C3=A9liore=20l?= =?UTF-8?q?=E2=80=99API=20modelValue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - cf. documentation BREAKING CHANGE: `modelValue` contient un tableau des `value` --- demo-app/views/AppForm.vue | 44 ++++++++++++++- docs/docs-demo/DsfrCheckboxSetV7Demo.vue | 42 ++++++++++++++ docs/guide/migrations.md | 19 ++++++- .../DsfrCheckbox/DsfrCheckbox.stories.ts | 3 + .../DsfrCheckbox/DsfrCheckbox.types.ts | 6 +- src/components/DsfrCheckbox/DsfrCheckbox.vue | 13 ++--- .../DsfrCheckbox/DsfrCheckboxSet.md | 12 +++- .../DsfrCheckbox/DsfrCheckboxSet.spec.ts | 29 ++++++++-- .../DsfrCheckbox/DsfrCheckboxSet.stories.ts | 55 +++++++++++-------- .../DsfrCheckbox/DsfrCheckboxSet.vue | 20 +++---- .../docs-demo/DsfrCheckboxDemo.vue | 10 +++- .../docs-demo/DsfrCheckboxSetDemo.vue | 33 ++++++----- 12 files changed, 211 insertions(+), 75 deletions(-) create mode 100644 docs/docs-demo/DsfrCheckboxSetV7Demo.vue 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.stories.ts b/src/components/DsfrCheckbox/DsfrCheckbox.stories.ts index 880a437c..ba52b49f 100644 --- a/src/components/DsfrCheckbox/DsfrCheckbox.stories.ts +++ b/src/components/DsfrCheckbox/DsfrCheckbox.stories.ts @@ -71,9 +71,11 @@ export const Checkbox = (args) => ({ :required="required" :small="small" :hint="hint" + :value="value" :name="name || 'name1'" v-model="modelValue" /> + {{ modelValue }} `, watch: { modelValue (newValue) { @@ -88,6 +90,7 @@ Checkbox.args = { small: false, label: 'Checkbox 1', name: 'name1', + value: 'name1', hint: 'Description 1', } Checkbox.play = async ({ canvasElement }) => { diff --git a/src/components/DsfrCheckbox/DsfrCheckbox.types.ts b/src/components/DsfrCheckbox/DsfrCheckbox.types.ts index cdba0503..9c4150c2 100644 --- a/src/components/DsfrCheckbox/DsfrCheckbox.types.ts +++ b/src/components/DsfrCheckbox/DsfrCheckbox.types.ts @@ -4,7 +4,9 @@ export type DsfrCheckboxProps = { id?: string name: string required?: boolean - modelValue?: boolean + value: unknown + checked?: boolean + modelValue: Array small?: boolean inline?: boolean label?: string @@ -23,6 +25,6 @@ export type DsfrCheckboxSetProps = { validMessage?: string legend?: string options?: (DsfrCheckboxProps & InputHTMLAttributes)[] - modelValue?: string[] + modelValue?: Array ariaInvalid?: boolean } diff --git a/src/components/DsfrCheckbox/DsfrCheckbox.vue b/src/components/DsfrCheckbox/DsfrCheckbox.vue index 90209bae..48622eb1 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()