2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

laravel8 jetstreamでbootstrap5を利用してハンバーガーボタンが効かない対処

Posted at

laravel8 のログイン認証一式をやってくれるjetstreamですが
livewire/inertiaどちらを選んでもCSSとしてtailwindがベースとなるようです。
livewireがbladeベースのテンプレートファイルで画面を実装するフレームワーク
inertiaがvueやreactなどのSPAで画面を実装するフレームワーク用だそう。
team機能を使う場合は--teamsをつける。

bash
$ composer require laravel/jetstream
# liveeireを使う場合
$ php artisan jetstream:install livewire
# liveeireでteamsを使う場合
$ php artisan jetstream:install livewire --teams
# inertiaを使う場合
$ php artisan jetstream:install inertia
# inertiaでteamsを使う場合
$ php artisan jetstream:install inertia --teams

このtailwindをbootstrap5で置き換えてくれるのが
nascent-africa/jetstrap

$ composer require nascent-africa/jetstrap
$ php artisan jetstrap:swap livewire --teams
$ npm install && npm run dev
$ php artisan migrate

以上でTOP画面からlogin/registerなどの画面
ログイン後のdashboard画面やプロフィール設定画面などが実装される。

問題はここからで
スマホだとレスポンシブの関係でヘッダーメニューが
三本線の「ハンバーガーボタン」で表現されるがこちらが反応しませんでした。

原因はbootstrap5の変更でdropdownメニューのdata属性が
data-*
data-bs-*に変わったのがjetstrapでは正しく置換されていないようでした。

対象となるボタンの実装されているファイルの以下の個所を変更

resources/views/navigation-menu.blade.php
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
            <span class="navbar-toggler-icon"></span>
        </button>
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?