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

Nested groups do not work. #222

Open
devilstars opened this issue Jul 12, 2018 · 4 comments
Open

Nested groups do not work. #222

devilstars opened this issue Jul 12, 2018 · 4 comments

Comments

@devilstars
Copy link

If I use example code:

Menu::make('MyNavBar', function($menu){
    $menu->group(['prefix' => 'pages', 'data-info' => 'test'], function($m){

        $m->add('About', 'about');

        $m->group(['prefix' => 'about', 'data-role' => 'navigation'], function($a){

            $a->add('Who we are', 'who-we-are?');
            $a->add('What we do?', 'what-we-do');
            $a->add('Our Goals', 'our-goals');
        });
    });
});

It gives me

<ul>
    <li data-info="test"><a href="http://blabla.test/pages/about">About</a></li>
    <li data-info="test" data-role="navigation"><a href="http://blabla.test/pages/about/who-we-are?">Who we are</a></li>
    <li data-info="test" data-role="navigation"><a href="http://blabla.test/pages/about/what-we-do">What we do?</a></li>
    <li data-info="test" data-role="navigation"><a href="http://blabla.test/pages/about/our-goals">Our Goals</a></li>
</ul>

Instead of

<ul>
    ...
    <li data-info="test">
        <a href="http://yourdomain.com/pages/about">About</a>
        <ul>
            <li data-info="test" data-role="navigation"><a href="http://yourdomain.com/pages/about/who-we-are"></a></li>
            <li data-info="test" data-role="navigation"><a href="http://yourdomain.com/pages/about/what-we-do"></a></li>
            <li data-info="test" data-role="navigation"><a href="http://yourdomain.com/pages/about/our-goals"></a></li>
        </ul>
    </li>
</ul>

Seems to be a bug.

@dustingraham
Copy link
Collaborator

https://github.com/lavary/laravel-menu#nested-groups

A menu group merges its own attribute with its parent group then shares them between its wrapped items:

Groups are not nested menus. Groups do not create a new level of ULs.

What you want is a nested menu.

Try this.... https://github.com/lavary/laravel-menu#advanced-usage

Another example...

            $about = $menu->add('About', ['url'  => 'about', 'class' => 'navbar navbar-about dropdown']);
            $about->attr(['class' => 'dropdown-toggle', 'data-toggle' => 'dropdown'])
                ->append('<b class="caret"></b>')
                ->prepend('<span class="glyphicon glyphicon-user"></span>');
            $about->add('Our Attorneys', ['route'  => 'attorneys'])
                ->active('attorneys/*/awesome');

The first $menu->add returns the $about element. From there you can add sub-items to that $about element with $about->add

@dustingraham dustingraham self-assigned this Jul 12, 2018
@devilstars
Copy link
Author

Groups are not nested menus. Groups do not create a new level of ULs.

So... there is an error in documentation? Because in example it gives

<ul>
    ...
    <li data-info="test">
        <a href="http://yourdomain.com/pages/about">About</a>
        <ul>
            <li data-info="test" data-role="navigation"><a href="http://yourdomain.com/pages/about/who-we-are"></a></li>
            <li data-info="test" data-role="navigation"><a href="http://yourdomain.com/pages/about/what-we-do"></a></li>
            <li data-info="test" data-role="navigation"><a href="http://yourdomain.com/pages/about/our-goals"></a></li>
        </ul>
    </li>
</ul>

@dustingraham dustingraham added bug and removed question labels Jul 13, 2018
@dustingraham
Copy link
Collaborator

Yes, bug in either documentation or implementation.

Did a quick test and I would have thought the following would work. But, it doesn't. So yes, something is wrong. Thanks for identifying this.

\Menu::make('sMenu', function($menu) {
    $menu->group(['prefix' => 'pages', 'data-info' => 'test'], function($m){
        $about = $m->add('About', 'about');
        $about->group(['prefix' => 'about', 'data-role' => 'navigation'], function($a){
            $a->add('Who we are', 'who-we-are?');
            $a->add('What we do?', 'what-we-do');
            $a->add('Our Goals', 'our-goals');
        });
    });
});

@nikita-nikolaevich
Copy link

#115 (comment)

Working version of the code

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

3 participants