lavary/laravel-menu

Active link and item classes

Opened this issue · 4 comments

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:

if ('item' == $this->builder->conf('active_element')) {

 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();
        }

$this->attributes['class'] = Builder::formatGroupClass(array('class' => $this->builder->conf('active_class')), $this->attributes);

$this->attributes['class'] = Builder::formatGroupClass(array('class' => $this->builder->conf('active_class_item')), $this->attributes);

$this->attributes['class'] = Builder::formatGroupClass(array('class' => $this->builder ? $this->builder->conf('active_class') : null), $this->attributes);

$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.