Skip to content

Commit

Permalink
MDL-62144 user menu: Accessibility
Browse files Browse the repository at this point in the history
Ensure user menu passes the accessibility tests.
  • Loading branch information
Damyon Wiese committed Oct 22, 2018
1 parent 5cccea6 commit 4fa885d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/outputcomponents.php
Expand Up @@ -4127,6 +4127,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
Expand Down Expand Up @@ -4184,6 +4190,16 @@ public function __construct(array $actions = array()) {
}
}

/**
* 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.
*
Expand Down Expand Up @@ -4306,10 +4322,17 @@ public function get_primary_actions(core_renderer $output = null) {
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'
);
Expand Down Expand Up @@ -4475,6 +4498,13 @@ public function export_for_template(renderer_base $output) {
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');
$actionicon = new pix_icon('t/edit_menu', '', 'moodle', ['class' => 'iconsmall actionmenu', 'title' => $primary->title]);
Expand Down
1 change: 1 addition & 0 deletions lib/outputrenderers.php
Expand Up @@ -3439,6 +3439,7 @@ public function user_menu($user = null, $withlinks = null) {
$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) {
Expand Down

0 comments on commit 4fa885d

Please sign in to comment.