Skip to content

Commit

Permalink
Add ability to use Bootstrap 5 (#279)
Browse files Browse the repository at this point in the history
Introduced a setting 'laravel-menu.settings.default.data_toggle_attribute'
which needs to be set to 'data-bs-toggle' when using bootstrap 5
(currently in beta).

Co-authored-by: Herbert Maschke <[email protected]>
  • Loading branch information
thyseus and Herbert Maschke authored Jan 19, 2021
1 parent 02c58d8 commit 8c57284
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![License](https://poser.pugx.org/lavary/laravel-menu/license.svg)](https://packagist.org/packages/lavary/laravel-menu)


A quick and easy way to create menus in [Laravel 6](http://laravel.com/)
A quick and easy way to create menus in [Laravel 6, 7 and 8](http://laravel.com/)

__For Laravel 4.x, check [version 1.5.0](https://github.com/lavary/laravel-menu/tree/v1.5.0)__

Expand Down Expand Up @@ -1359,6 +1359,8 @@ This is how your Bootstrap code is going to look like:
</nav>
```

In case you are using bootstrap 5 (currently in beta) you need to set the `data-toggle-attribute` option from `data-toggle` to `data-bs-toggle` in your `config/laravel-menu/settings.php`.

#### Adding class attributes to child items

Like adding a class to the menu `ul` and `ol`, classes can be added the submenu too. The three parameters to `asUl` are arrays as follows:
Expand Down
4 changes: 4 additions & 0 deletions src/Lavary/Menu/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ protected function bladeDirectives()
Blade::directive('lm_endattrs', function ($expression) {
return '<?php echo \Lavary\Menu\Builder::mergeStatic(ob_get_clean(), $lm_attrs); ?>';
});

Blade::directive('data_toggle_attribute', function ($expression) {
return config('laravel-menu.settings.default.data_toggle_attribute');
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@foreach($items as $item)
<li @lm_attrs($item) @if($item->hasChildren()) class="nav-item dropdown" @endif @lm_endattrs>
@if($item->link) <a @lm_attrs($item->link) @if($item->hasChildren()) class="nav-link dropdown-toggle" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" @else class="nav-link" @endif @lm_endattrs href="{!! $item->url() !!}">
@if($item->link) <a @lm_attrs($item->link) @if($item->hasChildren()) class="nav-link dropdown-toggle" role="button" @data_toggle_attribute="dropdown" aria-haspopup="true" aria-expanded="false" @else class="nav-link" @endif @lm_endattrs href="{!! $item->url() !!}">
{!! $item->title !!}
@if($item->hasChildren()) <b class="caret"></b> @endif
</a>
Expand Down
1 change: 1 addition & 0 deletions src/config/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
'cascade_data' => true,
'rest_base' => '', // string|array
'active_element' => 'item', // item|link
'data-toggle-attribute' => 'data-toggle',
),
);

0 comments on commit 8c57284

Please sign in to comment.