MDL-70173 output: All pages should have a heading

In MDL-63040, it was decided that the page header for the dashboad page
should be removed.
However, Based on Success Criteria 1.3.1 and 2.4.6 from the WebAIM's
WCAG 2 Checklist, all pages should have an <h1> element.
So I put an sr-only heading on the dashboard and all other pages, where
no page header is shown.
This commit is contained in:
Shamim Rezaie 2020-12-07 02:41:06 +11:00
parent d27c60a90a
commit 254aa09f40

View file

@ -4242,9 +4242,17 @@ EOD;
*/ */
protected function render_context_header(context_header $contextheader) { protected function render_context_header(context_header $contextheader) {
// Generate the heading first and before everything else as we might have to do an early return.
if (!isset($contextheader->heading)) {
$heading = $this->heading($this->page->heading, $contextheader->headinglevel);
} else {
$heading = $this->heading($contextheader->heading, $contextheader->headinglevel);
}
$showheader = empty($this->page->layout_options['nocontextheader']); $showheader = empty($this->page->layout_options['nocontextheader']);
if (!$showheader) { if (!$showheader) {
return ''; // Return the heading wrapped in an sr-only element so it is only visible to screen-readers.
return html_writer::div($heading, 'sr-only');
} }
// All the html stuff goes here. // All the html stuff goes here.
@ -4257,13 +4265,7 @@ EOD;
} }
// Headings. // Headings.
if (!isset($contextheader->heading)) { $html .= html_writer::tag('div', $heading, array('class' => 'page-header-headings'));
$headings = $this->heading($this->page->heading, $contextheader->headinglevel);
} else {
$headings = $this->heading($contextheader->heading, $contextheader->headinglevel);
}
$html .= html_writer::tag('div', $headings, array('class' => 'page-header-headings'));
// Buttons. // Buttons.
if (isset($contextheader->additionalbuttons)) { if (isset($contextheader->additionalbuttons)) {