MDL-77375 output: Allow additional options for dropdowns

This commit is contained in:
Shamim Rezaie 2023-05-26 03:50:13 +10:00
parent ba07bb42e1
commit 88f66617a0
2 changed files with 46 additions and 3 deletions

@ -4233,6 +4233,12 @@ class action_menu implements renderable, templatable {
*/
public $menutrigger = '';
/**
* An array of attributes added to the trigger element of the secondary menu.
* @var array
*/
public $triggerattributes = [];
/**
* Any extra classes for toggling to the secondary menu.
* @var string
@ -4520,6 +4526,22 @@ class action_menu implements renderable, templatable {
$this->attributessecondary['data-constraint'] = $ancestorselector;
}
/**
* Set the overflow constraint boundary of the dropdown menu.
* @see https://getbootstrap.com/docs/4.6/components/dropdowns/#options The 'boundary' option in the Bootstrap documentation
*
* @param string $boundary Accepts the values of 'viewport', 'window', or 'scrollParent'.
* @throws coding_exception
*/
public function set_boundary(string $boundary) {
if (!in_array($boundary, ['viewport', 'window', 'scrollParent'])) {
throw new coding_exception("HTMLElement reference boundaries are not supported." .
"Accepted boundaries are 'viewport', 'window', or 'scrollParent'.", DEBUG_DEVELOPER);
}
$this->triggerattributes['data-boundary'] = $boundary;
}
/**
* If you call this method the action menu will be displayed but will not be enhanced.
*
@ -4617,6 +4639,9 @@ class action_menu implements renderable, templatable {
$primary->attributes = array_map(function($key, $value) {
return [ 'name' => $key, 'value' => $value ];
}, array_keys($attributesprimary), $attributesprimary);
$primary->triggerattributes = array_map(function($key, $value) {
return [ 'name' => $key, 'value' => $value ];
}, array_keys($this->triggerattributes), $this->triggerattributes);
$actionicon = $this->actionicon;
if (!empty($this->menutrigger)) {

@ -21,8 +21,12 @@
Example context (json):
{
"text": "Example link text",
"actiontext": "Example link text",
"title": "Example link title",
"triggerrole": "button",
"triggerattributes": [
{"name": "data-boundary", "value": "window" }
],
"url": "http://example.com/link",
"classes": "icon menu-action",
"instance": "1",
@ -52,7 +56,7 @@
"component": null,
"title": "Dashboard"
},
"classes": "icon menu-action",
"classes": "menu-action",
"attributes": [
{"name": "role", "value": "menuitem"},
{"name": "data-title", "value": "mymoodle,admin"}
@ -79,7 +83,21 @@
}
}}
<div class="dropdown{{^secondary.items}} hidden{{/secondary.items}}">
<a href="#" tabindex="0" class="{{triggerextraclasses}} dropdown-toggle icon-no-margin" id="action-menu-toggle-{{instance}}" aria-label="{{title}}" data-toggle="dropdown" role="{{triggerrole}}" aria-haspopup="true" aria-expanded="false" aria-controls="action-menu-{{instance}}-menu">
<a
href="#"
tabindex="0"
class="{{triggerextraclasses}} dropdown-toggle icon-no-margin"
id="action-menu-toggle-{{instance}}"
aria-label="{{title}}"
data-toggle="dropdown"
role="{{triggerrole}}"
aria-haspopup="true"
aria-expanded="false"
aria-controls="action-menu-{{instance}}-menu"
{{#triggerattributes}}
{{name}}="{{value}}"
{{/triggerattributes}}
>
{{{actiontext}}}
{{{menutrigger}}}
{{#icon}}