Commit 093cb97f by Alexander Makarov

Merge pull request #4393 from kartik-v/patch-1

Better fix for Dropdown container options
parents 6dc056b3 2eb9cf80
......@@ -40,6 +40,11 @@ class Dropdown extends Widget
*/
public $encodeLabels = true;
/**
* @var array the HTML attributes for the widget container tag.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
protected $_containerOptions = [];
/**
* Initializes the widget.
......@@ -49,6 +54,7 @@ class Dropdown extends Widget
{
parent::init();
Html::addCssClass($this->options, 'dropdown-menu');
$this->_containerOptions = $this->options;
}
/**
......@@ -56,17 +62,16 @@ class Dropdown extends Widget
*/
public function run()
{
echo $this->renderItems($this->items, $this->options);
echo $this->renderItems($this->items);
}
/**
* Renders menu items.
* @param array $items the menu items to be rendered
* @param array $containerOptions the HTML attributes for the widget container tag
* @return string the rendering result.
* @throws InvalidConfigException if the label option is not specified in one of the items.
*/
protected function renderItems($items, $containerOptions)
protected function renderItems($items)
{
$lines = [];
foreach ($items as $i => $item) {
......@@ -88,13 +93,13 @@ class Dropdown extends Widget
$linkOptions['tabindex'] = '-1';
$content = Html::a($label, ArrayHelper::getValue($item, 'url', '#'), $linkOptions);
if (!empty($item['items'])) {
unset($containerOptions['id']);
$this->renderItems($item['items'], $containerOptions);
unset($this->_containerOptions['id']);
$this->renderItems($item['items']);
Html::addCssClass($options, 'dropdown-submenu');
}
$lines[] = Html::tag('li', $content, $options);
}
return Html::tag('ul', implode("\n", $lines), $this->options);
return Html::tag('ul', implode("\n", $lines), $this->_containerOptions);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment