Skip to content

Commit a387c9c

Browse files
authored
Merge pull request #7495 from nextcloud-libraries/backport/7483/stable8
[stable8] fix(NcRadioGroup): fieldsets always need a label for accessibility
2 parents 8e85f44 + 34abd62 commit a387c9c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/components/NcRadioGroup/NcRadioGroup.vue

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@ import { INSIDE_RADIO_GROUP_KEY } from './useNcRadioGroup.ts'
1010
1111
const props = defineProps<{
1212
/**
13-
* Optional visual label of the radio group
13+
* Label of the radio group (accessible name).
14+
* It can be hidden visually if needed using `hidden-label` prop.
1415
*/
15-
label?: string
16+
label: string
17+
18+
/**
19+
* If set the label of the button group will not be shown visually but only for accessibility purposes.
20+
*/
21+
labelHidden?: boolean
1622
1723
/**
1824
* Optional visual description of the radio group.
@@ -75,7 +81,7 @@ export default {
7581
:class="[{
7682
[$style.radioGroup_buttonVariant]: buttonVariant,
7783
}, $style.radioGroup]">
78-
<legend v-if="label" :class="$style.radioGroup__label">
84+
<legend :class="[$style.radioGroup__label, { 'hidden-visually': labelHidden }]">
7985
{{ label }}
8086
</legend>
8187
<p v-if="description" :id="descriptionId" :class="$style.radioGroup__description">
@@ -181,7 +187,7 @@ The radio group also allows to create a button like styling together with the `N
181187
<div>
182188
<h4>With text labels</h4>
183189
<div style="max-width: 400px">
184-
<NcRadioGroup v-model="alignment">
190+
<NcRadioGroup v-model="alignment" label="Example alignment" label-hidden>
185191
<NcRadioGroupButton label="Start" value="start" />
186192
<NcRadioGroupButton label="Center" value="center" />
187193
<NcRadioGroupButton label="End" value="end" />
@@ -192,7 +198,7 @@ The radio group also allows to create a button like styling together with the `N
192198

193199
<h4>With icons</h4>
194200
<div style="max-width: 250px">
195-
<NcRadioGroup v-model="alignment">
201+
<NcRadioGroup v-model="alignment" label="Example alignment with icons" label-hidden>
196202
<NcRadioGroupButton aria-label="Start" value="start">
197203
<template #icon>
198204
<NcIconSvgWrapper directional :path="mdiAlignHorizontalLeft" />

0 commit comments

Comments
 (0)