Skip to content

Commit

Permalink
feat(RadioGroup): add selected to label slot props (#1587)
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncdn authored Jul 23, 2024
1 parent 748e491 commit d18477d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/runtime/components/forms/RadioGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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 {
Expand All @@ -128,7 +132,8 @@ export default defineComponent({
return {
...option,
value: guessOptionValue(option),
label: guessOptionText(option)
label: guessOptionText(option),
selected: guessOptionSelected(option)
}
}
Expand Down

0 comments on commit d18477d

Please sign in to comment.