Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for setting the CSS class for the menu and its items #15

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 15 additions & 1 deletion Nav.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ class Nav extends Widget
* Defaults to `null` which means `<b class="caret"></b>` will be used. To disable the caret, set this property to be an empty string.
*/
public $dropDownCaret;
/**
* @var string the CSS class that will be assigned to the menu element.
* Defaults to 'nav'.
*/
public $menuCssClass = 'nav';
/**
* @var string the CSS class that will be assigned to each item element.
* Defaults to null, meaning no CSS class will be assigned.
*/
public $itemCssClass = null;


/**
Expand All @@ -116,7 +126,7 @@ public function init()
if ($this->dropDownCaret === null) {
$this->dropDownCaret = Html::tag('b', '', ['class' => 'caret']);
}
Html::addCssClass($this->options, 'nav');
Html::addCssClass($this->options, $this->menuCssClass);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such construction does not seem right: we have a $options, which allows specification of the 'class' and $menuCssClass for the specification of the class.
It seems either Html::addCssClass() usage should be abandonded or menuCssClass not introduced.

}

/**
Expand Down Expand Up @@ -189,6 +199,10 @@ public function renderItem($item)
if ($this->activateItems && $active) {
Html::addCssClass($options, 'active');
}

if ($this->itemCssClass !== null) {
Html::addCssClass($options, $this->itemCssClass);
}

return Html::tag('li', Html::a($label, $url, $linkOptions) . $items, $options);
}
Expand Down