feat(RadioGroup): add selected to label slot props (#1587)

This commit is contained in:
Cardona Simon
2024-07-23 14:54:18 +02:00
committed by GitHub
parent 748e49175d
commit d18477def5

View File

@@ -18,7 +18,7 @@
@change="onUpdate(option.value)"
>
<template #label>
<slot name="label" v-bind="{ option }" />
<slot name="label" v-bind="{ option, selected: option.selected }" />
</template>
</URadio>
</fieldset>
@@ -117,6 +117,10 @@ export default defineComponent({
return get(option, props.optionAttribute, get(option, props.valueAttribute))
}
const guessOptionSelected = (option: any) => {
return props.modelValue === guessOptionValue(option)
}
const normalizeOption = (option: any) => {
if (['string', 'number', 'boolean'].includes(typeof option)) {
return {
@@ -128,7 +132,8 @@ export default defineComponent({
return {
...option,
value: guessOptionValue(option),
label: guessOptionText(option)
label: guessOptionText(option),
selected: guessOptionSelected(option)
}
}