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

Active link and item classes #293

Open
ghost opened this issue Mar 27, 2022 · 4 comments
Open

Active link and item classes #293

ghost opened this issue Mar 27, 2022 · 4 comments

Comments

@ghost
Copy link

ghost commented Mar 27, 2022

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

@dustingraham
Copy link
Collaborator

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.

@ghost
Copy link
Author

ghost commented May 19, 2022

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
Copy link

How can I contribute with your team

@dustingraham
Copy link
Collaborator

A pull request is welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants