Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/Bootstrapper/DropdownButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ class DropdownButton extends RenderedObject
* @var bool Whether the button should drop up
*/
protected $dropup = false;

/**
* @var bool Whether the menu should align right
*/
protected $alignRight = false;

/**
* Set the label of the button
Expand Down Expand Up @@ -167,6 +172,18 @@ public function dropup()

return $this;
}

/**
* Sets the dropdown menu align right
*
* @return $this
*/
public function alignRight()
{
$this->alignRight = true;

return $this;
}

/**
* Creates a normal dropdown button
Expand Down Expand Up @@ -323,7 +340,13 @@ public function render()
$string .= "<button {$attributes}>{$this->label} <span class='caret'></span></button>";
}

$string .= "<ul class='dropdown-menu' role='menu' aria-labelledby='dLabel'>";
$string .= "<ul class='dropdown-menu";

if ($this->alignRight) {
$string .= " dropdown-menu-right";
}

$string .= "' role='menu' aria-labelledby='dLabel'>";
$string .= $this->renderItems();
$string .= "</ul>";
$string .= "</div>";
Expand Down
7 changes: 7 additions & 0 deletions tests/spec/Bootstrapper/DropdownButtonSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ function it_can_be_made_to_dropup()
);
}

function it_can_be_made_to_alignRight()
{
$this->alignRight()->render()->shouldBe(
"<div class='btn-group'><button class='btn btn-default dropdown-toggle' data-toggle='dropdown' type='button'> <span class='caret'></span></button><ul class='dropdown-menu dropdown-menu-right' role='menu' aria-labelledby='dLabel'></ul></div>"
);
}

function it_has_shortcut_methods()
{
$types = ['primary', 'danger', 'warning', 'success', 'info', 'normal'];
Expand Down