Active link and item classes
Opened this issue · 4 comments
Deleted user commented
It would be great if it would be possible to specify the active class for each element, the tests showed everything ok works
Config:
'default' => array(
'active_class_item' => 'open',
'active_class_link' => 'active',
'active_element' => 'item|link', // item|link
),
Code:
laravel-menu/src/Lavary/Menu/Item.php
Line 437 in 5255e71
if ('item' == $this->builder->conf('active_element')) {
$item->active();
} elseif('item|link' == $this->builder->conf('active_element')) {
$item->active();
$item->link->active();
}else{
$item->link->active();
}
laravel-menu/src/Lavary/Menu/Item.php
Line 473 in 5255e71
$this->attributes['class'] = Builder::formatGroupClass(array('class' => $this->builder->conf('active_class_item')), $this->attributes);
laravel-menu/src/Lavary/Menu/Link.php
Line 61 in 5255e71
$this->attributes['class'] = Builder::formatGroupClass(array('class' => $this->builder ? $this->builder->conf('active_class_link') : null), $this->attributes);
It's a small thing but necessary
dustingraham commented
Good idea. I wonder if it could be improved to fallback to active_class if the more granular active_class_link isn't set.
If someone wants to make this into a PR I would review.
Deleted user commented
It's better this way:
'default' => array(
'active_class_item' => 'open',
'active_class_link' => 'active',
'active_element' => ['item', 'link'], // item, link
),
CODE:
...
// Check to see which element should have class 'active' set.
if (in_array('item', $this->builder->conf('active_element')))
$item->active();
if (in_array('link', $this->builder->conf('active_element')))
$item->link->active();
...
Tran-Quyen commented
How can I contribute with your team
dustingraham commented
A pull request is welcome.