MDL-62144 user menu: Accessibility

Ensure user menu passes the accessibility tests.
This commit is contained in:
Damyon Wiese
2018-10-22 10:42:28 +08:00
parent 191a1c7c23
commit a986cb4ba1
2 changed files with 31 additions and 0 deletions
+30
View File
@@ -4133,6 +4133,12 @@ class action_menu implements renderable, templatable {
*/
public $actiontext = null;
/**
* The string to use for the accessible label for the menu.
* @var array
*/
public $actionlabel = null;
/**
* An icon to use for the toggling the secondary menu (dropdown).
* @var actionicon
@@ -4190,6 +4196,16 @@ class action_menu implements renderable, templatable {
}
}
/**
* Sets the label for the menu trigger.
*
* @param string $label The text
* @return null
*/
public function set_action_label($label) {
$this->actionlabel = $label;
}
/**
* Sets the menu trigger text.
*
@@ -4312,10 +4328,17 @@ class action_menu implements renderable, templatable {
if ($this->actiontext) {
$string = $this->actiontext;
}
$label = '';
if ($this->actionlabel) {
$label = $this->actionlabel;
} else {
$label = $title;
}
$actions = $this->primaryactions;
$attributes = array(
'class' => implode(' ', $linkclasses),
'title' => $title,
'aria-label' => $label,
'id' => 'action-menu-toggle-'.$this->instance,
'role' => 'menuitem'
);
@@ -4481,6 +4504,13 @@ class action_menu implements renderable, templatable {
if (!empty($this->menutrigger)) {
$primary->menutrigger = $this->menutrigger;
$primary->triggerextraclasses = $this->triggerextraclasses;
if ($this->actionlabel) {
$primary->title = $this->actionlabel;
} else if ($this->actiontext) {
$primary->title = $this->actiontext;
} else {
$primary->title = strip_tags($this->menutrigger);
}
} else {
$primary->title = get_string('actionsmenu');
$iconattributes = ['class' => 'iconsmall actionmenu', 'title' => $primary->title];
+1
View File
@@ -3405,6 +3405,7 @@ EOD;
$am->set_menu_trigger(
$returnstr
);
$am->set_action_label(get_string('usermenu'));
$am->set_alignment(action_menu::TR, action_menu::BR);
$am->set_nowrap_on_items();
if ($withlinks) {