Active link and item classes
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: https://github.com/lavary/laravel-menu/blob/5255e715912b50127b296da7410bd97468bf5e40/src/Lavary/Menu/Item.php#L437
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();
}
https://github.com/lavary/laravel-menu/blob/5255e715912b50127b296da7410bd97468bf5e40/src/Lavary/Menu/Item.php#L473
$this->attributes['class'] = Builder::formatGroupClass(array('class' => $this->builder->conf('active_class_item')), $this->attributes);
https://github.com/lavary/laravel-menu/blob/5255e715912b50127b296da7410bd97468bf5e40/src/Lavary/Menu/Link.php#L61
$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
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.
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();
...
How can I contribute with your team
A pull request is welcome.