Skip to content

Commit 8c57284

Browse files
thyseusHerbert Maschke
andauthored
Add ability to use Bootstrap 5 (#279)
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]>
1 parent 02c58d8 commit 8c57284

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![License](https://poser.pugx.org/lavary/laravel-menu/license.svg)](https://packagist.org/packages/lavary/laravel-menu)
66

77

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

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

@@ -1359,6 +1359,8 @@ This is how your Bootstrap code is going to look like:
13591359
</nav>
13601360
```
13611361

1362+
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`.
1363+
13621364
#### Adding class attributes to child items
13631365

13641366
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:

src/Lavary/Menu/ServiceProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ protected function bladeDirectives()
8080
Blade::directive('lm_endattrs', function ($expression) {
8181
return '<?php echo \Lavary\Menu\Builder::mergeStatic(ob_get_clean(), $lm_attrs); ?>';
8282
});
83+
84+
Blade::directive('data_toggle_attribute', function ($expression) {
85+
return config('laravel-menu.settings.default.data_toggle_attribute');
86+
});
8387
}
8488

8589
/**

src/Lavary/Menu/resources/views/bootstrap-navbar-items.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@foreach($items as $item)
22
<li @lm_attrs($item) @if($item->hasChildren()) class="nav-item dropdown" @endif @lm_endattrs>
3-
@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() !!}">
3+
@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() !!}">
44
{!! $item->title !!}
55
@if($item->hasChildren()) <b class="caret"></b> @endif
66
</a>

src/config/settings.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
'cascade_data' => true,
1010
'rest_base' => '', // string|array
1111
'active_element' => 'item', // item|link
12+
'data-toggle-attribute' => 'data-toggle',
1213
),
1314
);

0 commit comments

Comments
 (0)