MDL-67683 blocks: Do not assign a complementary role for blocks

Blocks are contained in an <aside> which has a default ARIA role of
"complementary", a top-level landmark. So assigning a "complementary"
role for block instances is not needed. As blocks are already in a
<section> tag which has a default role of "region", there's no need
to override the ARIA role, unless specified by the block plugin.

Read more at:
https://www.w3.org/WAI/ARIA/apg/practices/landmark-regions/
This commit is contained in:
Jun Pataleta
2025-02-03 15:54:49 +08:00
parent 10736389fa
commit e671b1ff0b
3 changed files with 12 additions and 10 deletions
+9 -7
View File
@@ -446,8 +446,11 @@ class block_base {
$attributes = array(
'id' => 'inst' . $this->instance->id,
'class' => 'block_' . $this->name() . ' block',
'role' => $this->get_aria_role()
);
$ariarole = $this->get_aria_role();
if ($ariarole) {
$attributes['role'] = $ariarole;
}
if ($this->hide_header()) {
$attributes['class'] .= ' no-header';
}
@@ -739,20 +742,19 @@ EOD;
* a landmark child.
*
* Options are as follows:
* - application
* - landmark
* - application
* - banner
* - complementary
* - contentinfo
* - form
* - main
* - navigation
* - search
*
* Please do not use top-level landmark roles such as 'banner', 'complementary', 'contentinfo', or 'main'. Read more at
* {@link https://www.w3.org/WAI/ARIA/apg/practices/landmark-regions/ ARIA Authoring Practices Guide - Landmark Regions}
*
* @return string
*/
public function get_aria_role() {
return 'complementary';
return 'region';
}
/**
+1 -1
View File
@@ -1504,7 +1504,7 @@ class core_renderer extends renderer_base {
$context->skiptitle = strip_tags($bc->title);
$context->showskiplink = !empty($context->skiptitle);
$context->arialabel = $bc->arialabel;
$context->ariarole = !empty($bc->attributes['role']) ? $bc->attributes['role'] : 'complementary';
$context->ariarole = !empty($bc->attributes['role']) ? $bc->attributes['role'] : '';
$context->class = $bc->attributes['class'];
$context->type = $bc->attributes['data-block'];
$context->title = $bc->title;
+2 -2
View File
@@ -7,7 +7,7 @@
"class": "block block_html",
"showskiplink": true,
"type": "html",
"ariarole": "complementary",
"ariarole": "",
"title": "Test block",
"blockinstanceid": 1,
"content": "<p>Hello block world!</p>"
@@ -22,7 +22,7 @@
{{! Start Block Container }}
<section id="{{id}}"
class="{{#hidden}}hidden{{/hidden}} {{class}} {{#hascontrols}}block_with_controls{{/hascontrols}} card mb-3"
role="{{ariarole}}"
{{#ariarole}}role="{{.}}"{{/ariarole}}
data-block="{{type}}"
data-instance-id="{{blockinstanceid}}"
{{#arialabel}}