a11y: add group role to blocks (#88620)
gitea/wcs/pipeline/head This commit looks good Details

This commit is contained in:
Frédéric Péters 2024-03-25 13:11:16 +01:00
parent 4d5b309986
commit 6d6bae428e
2 changed files with 15 additions and 1 deletions

View File

@ -498,6 +498,16 @@ class BlockWidget(WidgetList):
**kwargs,
)
@property
def a11y_labelledby(self):
return bool(self.title and self.label_display != 'hidden')
@property
def a11y_role(self):
if len([x for x in (self.block.fields or []) if not x.is_no_data_field]) > 1:
return 'group'
return None
def set_value(self, value):
from .fields.block import BlockRowValue
@ -566,7 +576,9 @@ class BlockWidget(WidgetList):
def render_title(self, title):
attrs = {'id': 'form_label_%s' % self.get_name_for_id()}
if not title or self.label_display == 'hidden':
return htmltag('span', **attrs) + htmltext('</span>')
# add a tag even if there's no label to display as it's uses as an anchor point
# for links to errors.
return htmltag('div', **attrs) + htmltext('</div>')
if self.label_display == 'normal':
return super().render_title(title)

View File

@ -1,3 +1,5 @@
{% extends "qommon/forms/widget.html" %}
{% block widget-css-classes %}{{ block.super }} {% if widget.had_add_clicked %}wcs-block-add-clicked{% endif %} {% if widget.remove_button %}wcs-block-with-remove-button{% endif %}{% endblock %}
{% block widget-attrs %}id="form_{{ widget.field.id }}" {{ block.super }}{% endblock %}