mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
MDL-48026 output: action_menu no wrap improvement
Action menu output component has a new method set_nowrap_on_items that sets a property to toggle nowrap on menu items. That can be used to avoid problems when the menu appears within an absolutely positioned or floated element.
This commit is contained in:
parent
ac4ed127de
commit
a2a9468f01
@ -3401,6 +3401,34 @@ class action_menu implements renderable {
|
||||
public function will_be_enhanced() {
|
||||
return isset($this->attributes['data-enhance']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets nowrap on items. If true menu items should not wrap lines if they are longer than the available space.
|
||||
*
|
||||
* This property can be useful when the action menu is displayed within a parent element that is either floated
|
||||
* or relatively positioned.
|
||||
* In that situation the width of the menu is determined by the width of the parent element which may not be large
|
||||
* enough for the menu items without them wrapping.
|
||||
* This disables the wrapping so that the menu takes on the width of the longest item.
|
||||
*
|
||||
* @param bool $value If true nowrap gets set, if false it gets removed. Defaults to true.
|
||||
*/
|
||||
public function set_nowrap_on_items($value = true) {
|
||||
$class = 'nowrap-items';
|
||||
if (!empty($this->attributes['class'])) {
|
||||
$pos = strpos($this->attributes['class'], $class);
|
||||
if ($value === true && $pos === false) {
|
||||
// The value is true and the class has not been set yet. Add it.
|
||||
$this->attributes['class'] .= ' '.$class;
|
||||
} else if ($value === false && $pos !== false) {
|
||||
// The value is false and the class has been set. Remove it.
|
||||
$this->attributes['class'] = substr($this->attributes['class'], $pos, strlen($class));
|
||||
}
|
||||
} else if ($value) {
|
||||
// The value is true and the class has not been set yet. Add it.
|
||||
$this->attributes['class'] = $class;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2174,6 +2174,10 @@ img#persona_signin {
|
||||
&.align-bl-tr {bottom: 100%;left:100%;}
|
||||
&.align-br-tr {bottom: 100%;right: 0;margin-bottom: 4px;}
|
||||
}
|
||||
/** no wrap is set - prevent menu items from wrapping **/
|
||||
&.nowrap-items .menu > li {
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
.block .moodle-actionmenu {
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user