Skip to content

Commit

Permalink
MDL-48026 output: action_menu no wrap improvement
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Sam Hemelryk committed Nov 3, 2014
1 parent ac4ed12 commit a2a9468
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
28 changes: 28 additions & 0 deletions lib/outputcomponents.php
Expand Up @@ -3401,6 +3401,34 @@ public function do_not_enhance() {
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;
}
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions theme/bootstrapbase/less/moodle/core.less
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion theme/bootstrapbase/style/moodle.css

Large diffs are not rendered by default.

0 comments on commit a2a9468

Please sign in to comment.