-
-
Notifications
You must be signed in to change notification settings - Fork 99
Add support for Bootstrap 4 #64
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
Conversation
- Enable custom tag - Added option to not wrap links in <li> - Added option to set active class on link
Hi @mrk-j, Big thanks for this PR! Looking good, but I have a few comments, could you go through these before I merge?
Also, I'd greatly appreciate if if you could add these new methods to the docs. No sweat if you don't have any extra time for this. |
Hey @sebastiandedeyne, I made the changes as you requested, I set the defaults of both methods to Let me know what you think. If the PR is merged I will update the docs accordingly. |
Looks great, huge thanks for this! 🎉 |
I ended up making some more API changes to open up more rendering options. Check out the release notes for the details: https://github.com/spatie/menu/releases/tag/2.5.0 |
I've been working to set up this library with Bootstrap 4; however, I've had some difficulties. This PR and the initial message were great to get me started. Using that and the changelog referenced I got something that 90% works - except one small bug. I'm wondering if this issue has another solution or would require a new feature. First I'll explain and show the issue I'm dealing with. Here is an updated equivalent to the OP snippet:
So the subnav macro generates our @mrk-j are you still using this library to generate BS4 based menus with dropdowns - if so, do you have the same issue or is there a work around you use? |
I just realized that looking it over #78 maybe related to the issue I'm describing. If that's the case then the solutions should be the same. |
We use the library like this: $menuBuilder = MenuBuilder::new()->addClass('navbar-nav');
$submenu = MenuBuilder::new()
->addClass('dropdown-menu')
->setWrapperTag('div')
->withoutParentTag(false)
->setActiveClassOnLink()
->addParentClass('nav-item')
->addParentClass('dropdown')
->setAttributes(['aria-labelledby' => 'navbarDropdownMenuLink']);
$submenu->add(Link::to('/page', 'Item')->addClass('dropdown-item'));
$link = Link::to('/url', 'Dropdown')
->addClass('nav-link')
->addClass('dropdown-toggle')
->setAttribute('id', 'navbarDropdownMenuLink')
->setAttribute('role', 'button')
->setAttribute('data-toggle', 'dropdown')
->setAttribute('aria-haspopup', 'true')
->setAttribute('aria-expanded', 'false');
$menuBuilder->submenu($link, $submenu); This results in: <ul class="navbar-nav">
<li class="nav-item dropdown">
<a href="/url" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="nav-link dropdown-toggle">Dropdown</a>
<div aria-labelledby="navbarDropdownMenuLink" class="dropdown-menu">
<a href="/page" class="dropdown-item">Item</a>
</div>
</li>
</ul> |
Ahh. @mrk-j I see thank you so much! So instead of letting the 'main' menu appling the |
When merged this PR adds support for Bootstrap 4.
We added 3 new methods for the
Menu
class:setTagName
enables using another element as an<ul>
setWrapLinksInList
can disable automatic the wrapping of links in<li>
'ssetActiveClassOnLink
can set theactiveClass
on the link instead of the<li>
To set the active class on the link we assume that the item supplied to
renderItem
implementsHasHtmlAttributes
. I think it is pretty safe to do so, but to be safe we added a check to see if the item implementsHasHtmlAttributes
.The syntax to render a Bootstrap 4 menu looks like this: