diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index 2e941ab0f8e5b..a39f924a34c83 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -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 @@ -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. * @@ -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' ); @@ -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]); diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index cffb473ad19e8..38d14473789cd 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -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) {