MDL-74800 core: action menu role fix

The action menu could have a role button or menubar depending on the
number of options available.
This commit is contained in:
Jun Pataleta
2022-08-08 14:46:42 +02:00
committed by Ferran Recio
parent dc63d643b8
commit 950d617aec
4 changed files with 20 additions and 3 deletions
+12
View File
@@ -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'])) {