@@ -14,14 +14,15 @@ const modelValue = defineModel<string>({ required: false, default: '' })
1414
1515const props = defineProps <{
1616 /**
17- * If no visual `label` is set, then at least this aria label of the radio group must be set for accessibility.
17+ * Label of the radio group (accessible name).
18+ * It can be hidden visually if needed using `hidden-label` prop.
1819 */
19- ariaLabel ? : string | undefined
20+ label : string
2021
2122 /**
22- * Optional visual label of the radio group
23+ * If set the label of the button group will not be shown visually but only for accessibility purposes.
2324 */
24- label ? : string
25+ labelHidden ? : boolean
2526
2627 /**
2728 * Optional visual description of the radio group.
@@ -49,10 +50,8 @@ provide(INSIDE_RADIO_GROUP_KEY, computed(() => ({
4950})))
5051
5152watchEffect (() => {
52- if (! props .ariaLabel && ! props .label ) {
53- warn (' [NcRadioGroup] Either a visual "label" or an "ariaLabel" must be specified.' )
54- } else if (props .ariaLabel !== undefined && props .label ) {
55- warn (' [NcRadioGroup] If a visual "label" is used then no "ariaLabel" should be specified, the accessible name is already inferred from the "label".' )
53+ if (! props .label ) {
54+ warn (' [NcRadioGroup] For accessibility reasons a proper "label" has to be set.' )
5655 }
5756})
5857
@@ -80,12 +79,11 @@ function onUpdate(value: string) {
8079
8180<template >
8281 <fieldset
83- :aria-label
8482 :aria-describedby =" description ? descriptionId : undefined"
8583 :class =" [{
8684 [$style.radioGroup_buttonVariant]: buttonVariant,
8785 }, $style.radioGroup]" >
88- <legend v-if = " label " :class =" $style.radioGroup__label" >
86+ <legend :class =" [ $style.radioGroup__label, { 'hidden-visually': labelHidden }] " >
8987 {{ label }}
9088 </legend >
9189 <p v-if =" description" :id =" descriptionId" :class =" $style.radioGroup__description" >
@@ -188,7 +186,7 @@ The radio group also allows to create a button like styling together with the `N
188186 <div>
189187 <h4>With text labels</h4>
190188 <div style="max-width: 400px">
191- <NcRadioGroup v-model="alignment" aria- label="Example alignment">
189+ <NcRadioGroup v-model="alignment" label="Example alignment" label-hidden >
192190 <NcRadioGroupButton label="Start" value="start" />
193191 <NcRadioGroupButton label="Center" value="center" />
194192 <NcRadioGroupButton label="End" value="end" />
@@ -199,7 +197,7 @@ The radio group also allows to create a button like styling together with the `N
199197
200198 <h4>With icons</h4>
201199 <div style="max-width: 250px">
202- <NcRadioGroup v-model="alignment" aria- label="Example alignment with icons">
200+ <NcRadioGroup v-model="alignment" label="Example alignment with icons" label-hidden >
203201 <NcRadioGroupButton aria-label="Start" value="start">
204202 <template #icon>
205203 <NcIconSvgWrapper directional :path="mdiAlignHorizontalLeft" />
0 commit comments