diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index c1b22e185f4..f1b6caa0d5a 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -4577,6 +4577,12 @@ class action_menu implements renderable, templatable { */ public function export_for_template(renderer_base $output) { $data = new stdClass(); + // Assign a role of menubar to this action menu when: + // - it contains 2 or more primary actions; or + // - if it contains a primary action and secondary actions. + if (count($this->primaryactions) > 1 || (!empty($this->primaryactions) && !empty($this->secondaryactions))) { + $this->attributes['role'] = 'menubar'; + } $attributes = $this->attributes; $attributesprimary = $this->attributesprimary; $attributessecondary = $this->attributessecondary; @@ -4617,6 +4623,12 @@ class action_menu implements renderable, templatable { $actionicon = new pix_icon('t/edit_menu', '', 'moodle', $iconattributes); } + // If the menu trigger is within the menubar, assign a role of menuitem. Otherwise, assign as a button. + $primary->triggerrole = 'button'; + if (isset($attributes['role']) && $attributes['role'] === 'menubar') { + $primary->triggerrole = 'menuitem'; + } + if ($actionicon instanceof pix_icon) { $primary->icon = $actionicon->export_for_pix(); if (!empty($actionicon->attributes['alt'])) { diff --git a/lib/templates/action_menu.mustache b/lib/templates/action_menu.mustache index f1016970303..34998b9291c 100644 --- a/lib/templates/action_menu.mustache +++ b/lib/templates/action_menu.mustache @@ -38,7 +38,7 @@ } } }} -