mirror of
https://github.com/moodle/moodle.git
synced 2025-05-01 14:09:01 +02:00
MDL-77375 output: Allow additional options for dropdowns
This commit is contained in:
parent
ba07bb42e1
commit
88f66617a0
lib
@ -4233,6 +4233,12 @@ class action_menu implements renderable, templatable {
|
|||||||
*/
|
*/
|
||||||
public $menutrigger = '';
|
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.
|
* Any extra classes for toggling to the secondary menu.
|
||||||
* @var string
|
* @var string
|
||||||
@ -4520,6 +4526,22 @@ class action_menu implements renderable, templatable {
|
|||||||
$this->attributessecondary['data-constraint'] = $ancestorselector;
|
$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.
|
* 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) {
|
$primary->attributes = array_map(function($key, $value) {
|
||||||
return [ 'name' => $key, 'value' => $value ];
|
return [ 'name' => $key, 'value' => $value ];
|
||||||
}, array_keys($attributesprimary), $attributesprimary);
|
}, 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;
|
$actionicon = $this->actionicon;
|
||||||
if (!empty($this->menutrigger)) {
|
if (!empty($this->menutrigger)) {
|
||||||
|
@ -21,8 +21,12 @@
|
|||||||
|
|
||||||
Example context (json):
|
Example context (json):
|
||||||
{
|
{
|
||||||
"text": "Example link text",
|
"actiontext": "Example link text",
|
||||||
"title": "Example link title",
|
"title": "Example link title",
|
||||||
|
"triggerrole": "button",
|
||||||
|
"triggerattributes": [
|
||||||
|
{"name": "data-boundary", "value": "window" }
|
||||||
|
],
|
||||||
"url": "http://example.com/link",
|
"url": "http://example.com/link",
|
||||||
"classes": "icon menu-action",
|
"classes": "icon menu-action",
|
||||||
"instance": "1",
|
"instance": "1",
|
||||||
@ -52,7 +56,7 @@
|
|||||||
"component": null,
|
"component": null,
|
||||||
"title": "Dashboard"
|
"title": "Dashboard"
|
||||||
},
|
},
|
||||||
"classes": "icon menu-action",
|
"classes": "menu-action",
|
||||||
"attributes": [
|
"attributes": [
|
||||||
{"name": "role", "value": "menuitem"},
|
{"name": "role", "value": "menuitem"},
|
||||||
{"name": "data-title", "value": "mymoodle,admin"}
|
{"name": "data-title", "value": "mymoodle,admin"}
|
||||||
@ -79,7 +83,21 @@
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
<div class="dropdown{{^secondary.items}} hidden{{/secondary.items}}">
|
<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}}}
|
{{{actiontext}}}
|
||||||
{{{menutrigger}}}
|
{{{menutrigger}}}
|
||||||
{{#icon}}
|
{{#icon}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user