Skip to content

Commit

Permalink
Allow adding dropdownMenu classes
Browse files Browse the repository at this point in the history
  • Loading branch information
juniwalk authored Mar 28, 2024
1 parent 68c8569 commit f3d97e5
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/UI/Actions/Controls/Dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,34 @@ class Dropdown extends UIControl implements Action
{
use Actions, Control;

private Html $menu;

public function __construct(
private string $name,
Stringable|string|null $label = null,
) {
$this->control = $this->addAction(new Button('_btn', $label, '#'));
$this->name = Strings::webalize($name);
$this->menu = Html::el('div');

$this->name = Strings::webalize($name);
$this->setParent(null, $this->name);
}


public function addMenuClass($class): static
{
$this->menu->addClass($class);
return $this;
}


public function create(): Html
{
$dropdownMenu = Html::el('div class="dropdown-menu"');
$button = $this->getControl()->addClass('dropdown-toggle')
->data('toggle', 'dropdown');

$this->menu->addClass('dropdown-menu');

foreach ($this->getActions() as $action) {
if ($action === $this->control) {
continue;
Expand All @@ -53,11 +64,11 @@ public function create(): Html
$element->addClass('ajax');
}

$dropdownMenu->addHtml($element);
$this->menu->addHtml($element);
}

return Html::el('div class="btn-group" role="group"')
->addHtml($button)->addHtml($dropdownMenu);
->addHtml($button)->addHtml($this->menu);
}


Expand Down

0 comments on commit f3d97e5

Please sign in to comment.