chore(RadioGroup): expose modeValue in label / description slots

This commit is contained in:
Benjamin Canac
2024-06-10 11:41:33 +02:00
parent 0f2da5bb15
commit b56151e144

View File

@@ -28,7 +28,7 @@ export interface RadioGroupProps<T> extends Omit<RadioGroupRootProps, 'asChild'
export interface RadioGroupEmits extends RadioGroupRootEmits {} export interface RadioGroupEmits extends RadioGroupRootEmits {}
type SlotProps<T> = (props: { item: T }) => any type SlotProps<T> = (props: { item: T, modelValue?: string }) => any
export interface RadioGroupSlots<T> { export interface RadioGroupSlots<T> {
legend(): any legend(): any
@@ -84,6 +84,7 @@ const normalizedItems = computed(() => {
<template> <template>
<RadioGroupRoot <RadioGroupRoot
:id="id" :id="id"
v-slot="{ modelValue }"
v-bind="rootProps" v-bind="rootProps"
:name="name" :name="name"
:disabled="disabled" :disabled="disabled"
@@ -110,10 +111,10 @@ const normalizedItems = computed(() => {
<div :class="ui.wrapper()"> <div :class="ui.wrapper()">
<Label :class="ui.label()" :for="item.id"> <Label :class="ui.label()" :for="item.id">
<slot name="label" :item="item">{{ item.label }}</slot> <slot name="label" :item="item" :model-value="modelValue">{{ item.label }}</slot>
</Label> </Label>
<p v-if="item.description || !!slots.description" :class="ui.description()"> <p v-if="item.description || !!slots.description" :class="ui.description()">
<slot name="description" :item="item"> <slot name="description" :item="item" :model-value="modelValue">
{{ item.description }} {{ item.description }}
</slot> </slot>
</p> </p>