a11y: add aria-describedby to radio buttons (#71076) #296

Merged
fpeters merged 1 commits from wip/71076-radiogroup-described-by into main 2023-05-12 09:21:20 +02:00
1 changed files with 6 additions and 1 deletions

View File

@ -272,13 +272,18 @@ class RadiobuttonsWidget(quixote.form.RadiobuttonsWidget):
has_inside_labels = True
a11y_labelledby = True
a11y_role = 'group'
content_extra_attributes = {'role': 'radiogroup'}
def __init__(self, name, value=None, **kwargs):
self.extra_css_class = kwargs.pop('extra_css_class', None)
self.options_with_attributes = kwargs.pop('options_with_attributes', None)
super().__init__(name, value=value, **kwargs)
@property
def content_extra_attributes(self):
content_extra_attributes = {'role': 'radiogroup'}
content_extra_attributes['aria-describedby'] = f'form_label_{self.get_name_for_id()}'
return content_extra_attributes
def get_options(self):
options = self.options_with_attributes or self.options
for option in options: