From 6352bfd5d5bc2840e863b50c97bc4ee6f4ece474 Mon Sep 17 00:00:00 2001 From: Evan Schleret Date: Thu, 16 Jul 2026 20:32:25 +0200 Subject: [PATCH 1/2] feat(RadioGroup): add custom item slots --- .../RadioGroupCustomSlotExample.vue | 35 ++++++++++++++ docs/content/docs/2.components/radio-group.md | 16 +++++++ src/runtime/components/RadioGroup.vue | 47 ++++++++++++++----- test/components/RadioGroup.spec.ts | 45 ++++++++++++++++++ 4 files changed, 131 insertions(+), 12 deletions(-) create mode 100644 docs/app/components/content/examples/radio-group/RadioGroupCustomSlotExample.vue diff --git a/docs/app/components/content/examples/radio-group/RadioGroupCustomSlotExample.vue b/docs/app/components/content/examples/radio-group/RadioGroupCustomSlotExample.vue new file mode 100644 index 0000000000..24d0aba148 --- /dev/null +++ b/docs/app/components/content/examples/radio-group/RadioGroupCustomSlotExample.vue @@ -0,0 +1,35 @@ + + + diff --git a/docs/content/docs/2.components/radio-group.md b/docs/content/docs/2.components/radio-group.md index 40fc431639..ff97d8649c 100644 --- a/docs/content/docs/2.components/radio-group.md +++ b/docs/content/docs/2.components/radio-group.md @@ -59,6 +59,7 @@ You can also pass an array of objects with the following properties: - `label?: string`{lang="ts-type"} - `description?: string`{lang="ts-type"} +- [`slot?: string`{lang="ts-type"}](#with-custom-slot) - [`value?: string`{lang="ts-type"}](#value-key) - `disabled?: boolean`{lang="ts-type"} - `class?: any`{lang="ts-type"} @@ -290,6 +291,21 @@ props: --- :: +## Examples + +### With custom slot + +Use the `slot` property to replace the label and description of a specific item with custom content. + +You will have access to the following slots: + +- `#{{ item.slot }}`{lang="ts-type"} +- `#content`{lang="ts-type"} to customize the content of items without a `slot` property + +Slots receive the `item` and `modelValue` properties. + +:component-example{name="radio-group-custom-slot-example"} + ## API ### Props diff --git a/src/runtime/components/RadioGroup.vue b/src/runtime/components/RadioGroup.vue index f1b7ab685b..e75ec578ad 100644 --- a/src/runtime/components/RadioGroup.vue +++ b/src/runtime/components/RadioGroup.vue @@ -13,6 +13,7 @@ export type RadioGroupValue = AcceptableValue export type RadioGroupItem = RadioGroupValue | { label?: string description?: string + slot?: string disabled?: boolean value?: RadioGroupValue class?: any @@ -80,14 +81,25 @@ export type RadioGroupEmits type NormalizeItem = Exclude - type SlotProps = (props: { item: NormalizeItem, modelValue: RadioGroupValue }) => VNode[] +type DynamicSlotProps = { + [K in T[number] extends infer Item + ? Item extends { slot?: infer Slot } + ? Slot extends string ? Slot : never + : never + : never]?: SlotProps +} + export interface RadioGroupSlots { legend?(props?: {}): VNode[] label?: SlotProps description?: SlotProps } + +type RadioGroupAllSlots = RadioGroupSlots & { + content?: SlotProps +} & DynamicSlotProps