MDL-68550 tablelib: Use aria-role=button

Use the aria-role=button for:
 - show/hide links
 - sort links
 - reset table preferences link
This commit is contained in:
Shamim Rezaie 2022-06-20 12:45:52 +10:00
parent 8e31a72c05
commit 178c51786c

View file

@ -1232,20 +1232,26 @@ class flexible_table {
$ariacontrols = trim($ariacontrols); $ariacontrols = trim($ariacontrols);
if (!empty($this->prefs['collapse'][$column])) { if (!empty($this->prefs['collapse'][$column])) {
$linkattributes = array('title' => get_string('show') . ' ' . strip_tags($this->headers[$index]), $linkattributes = [
'title' => get_string('show') . ' ' . strip_tags($this->headers[$index]),
'aria-expanded' => 'false', 'aria-expanded' => 'false',
'aria-controls' => $ariacontrols, 'aria-controls' => $ariacontrols,
'data-action' => 'show', 'data-action' => 'show',
'data-column' => $column); 'data-column' => $column,
'role' => 'button',
];
return html_writer::link($this->baseurl->out(false, array($this->request[TABLE_VAR_SHOW] => $column)), return html_writer::link($this->baseurl->out(false, array($this->request[TABLE_VAR_SHOW] => $column)),
$OUTPUT->pix_icon('t/switch_plus', null), $linkattributes); $OUTPUT->pix_icon('t/switch_plus', null), $linkattributes);
} else if ($this->headers[$index] !== NULL) { } else if ($this->headers[$index] !== NULL) {
$linkattributes = array('title' => get_string('hide') . ' ' . strip_tags($this->headers[$index]), $linkattributes = [
'title' => get_string('hide') . ' ' . strip_tags($this->headers[$index]),
'aria-expanded' => 'true', 'aria-expanded' => 'true',
'aria-controls' => $ariacontrols, 'aria-controls' => $ariacontrols,
'data-action' => 'hide', 'data-action' => 'hide',
'data-column' => $column); 'data-column' => $column,
'role' => 'button',
];
return html_writer::link($this->baseurl->out(false, array($this->request[TABLE_VAR_HIDE] => $column)), return html_writer::link($this->baseurl->out(false, array($this->request[TABLE_VAR_HIDE] => $column)),
$OUTPUT->pix_icon('t/switch_minus', null), $linkattributes); $OUTPUT->pix_icon('t/switch_minus', null), $linkattributes);
} }
@ -1664,6 +1670,7 @@ class flexible_table {
'data-sortable' => $this->is_sortable($column), 'data-sortable' => $this->is_sortable($column),
'data-sortby' => $column, 'data-sortby' => $column,
'data-sortorder' => $sortorder, 'data-sortorder' => $sortorder,
'role' => 'button',
]) . ' ' . $this->sort_icon($isprimary, $order); ]) . ' ' . $this->sort_icon($isprimary, $order);
} }
@ -1861,7 +1868,7 @@ class flexible_table {
$url = $this->baseurl->out(false, array($this->request[TABLE_VAR_RESET] => 1)); $url = $this->baseurl->out(false, array($this->request[TABLE_VAR_RESET] => 1));
$html = html_writer::start_div('resettable mdl-right'); $html = html_writer::start_div('resettable mdl-right');
$html .= html_writer::link($url, get_string('resettable')); $html .= html_writer::link($url, get_string('resettable'), ['role' => 'button']);
$html .= html_writer::end_div(); $html .= html_writer::end_div();
return $html; return $html;