mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
Fixed #34045 -- Improved accessibility of selecting items in admin changelist.
This adds "aria-label".
This commit is contained in:
committed by
Mariusz Felisiak
parent
6bdc3c58b6
commit
85366fbca7
@@ -36,9 +36,6 @@ class ActionForm(forms.Form):
|
||||
)
|
||||
|
||||
|
||||
checkbox = forms.CheckboxInput({"class": "action-select"}, lambda value: False)
|
||||
|
||||
|
||||
class AdminForm:
|
||||
def __init__(
|
||||
self,
|
||||
|
||||
@@ -13,7 +13,6 @@ from django.contrib.admin.checks import (
|
||||
InlineModelAdminChecks,
|
||||
ModelAdminChecks,
|
||||
)
|
||||
from django.contrib.admin.decorators import display
|
||||
from django.contrib.admin.exceptions import DisallowedModelAdminToField
|
||||
from django.contrib.admin.templatetags.admin_urls import add_preserved_filters
|
||||
from django.contrib.admin.utils import (
|
||||
@@ -962,12 +961,16 @@ class ModelAdmin(BaseModelAdmin):
|
||||
action_flag=DELETION,
|
||||
)
|
||||
|
||||
@display(description=mark_safe('<input type="checkbox" id="action-toggle">'))
|
||||
def action_checkbox(self, obj):
|
||||
"""
|
||||
A list_display column containing a checkbox widget.
|
||||
"""
|
||||
return helpers.checkbox.render(helpers.ACTION_CHECKBOX_NAME, str(obj.pk))
|
||||
attrs = {
|
||||
"class": "action-select",
|
||||
"aria-label": format_html(_("Select this object for an action - {}"), obj),
|
||||
}
|
||||
checkbox = forms.CheckboxInput(attrs, lambda value: False)
|
||||
return checkbox.render(helpers.ACTION_CHECKBOX_NAME, str(obj.pk))
|
||||
|
||||
@staticmethod
|
||||
def _get_action_description(func, name):
|
||||
|
||||
@@ -96,8 +96,12 @@ def result_headers(cl):
|
||||
|
||||
# if the field is the action checkbox: no sorting and special class
|
||||
if field_name == "action_checkbox":
|
||||
aria_label = _("Select all objects on this page for an action")
|
||||
yield {
|
||||
"text": text,
|
||||
"text": mark_safe(
|
||||
f'<input type="checkbox" id="action-toggle" '
|
||||
f'aria-label="{aria_label}">'
|
||||
),
|
||||
"class_attrib": mark_safe(' class="action-checkbox-column"'),
|
||||
"sortable": False,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user