Problem with navbar expanding

So i have this problem when i click navbar it dosent expand but when i go to a not found (#404) Page it works

and when i inspect the aria-expanded is set to true

but when i go to my main page i inspect the aria-expanded is set to false

this is my code:

NavBar::begin([

            'brandUrl' => Yii::$app->homeUrl,

            'options' => [

                'class' => 'navbar-inverse navbar-fixed-top',

            ],

        ]);

        $menuItems = [

            ['label' => 'Product', 'url' => ['product/index']],

        ];

        if (Yii::$app->user->isGuest) {

            $menuItems[] = ['label' => 'Register', 'url' => ['/site/register']];

            $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];

        } else {

            if(yii::$app->user->can('admin')){

            $menuItems[] = ['label' => 'Users', 'url' => ['new-user/index']];

            $menuItems[] = ['label' => 'Category', 'url' => ['category/index']];

            }

            $menuItems[] = 

                [

                'encode' => false,

                'label' =>  ('app'),

                'items' => 

                [['encode' => false, 'label' =>  ('app'),],

                ['label' => (Yii::$app->user->identity->username), 'options' => ['style' => 'margin-left: 93px; font-size: 15px; color: white; font-weight: bold; margin-top: 3px;'] ],

                ['label' => (Yii::$app->user->identity->email), 'options' => ['style' => 'margin-left: 38px; font-size: 15px; color: white; margin-top: -5px;'] ],

                ['encode' => false,'label' => Html::submitButton('<i class="far fa-user"></i>My Profile', ['style' => 'background-color: transparent; border: none; font-size: 15px;']), 'url' => ['/site/logout'],],

                ['encode' => false,'label' => Html::submitButton('<i class="far fa-comment-alt"></i>Messages', ['style' => 'background-color: transparent; border: none; font-size: 15px;']), 'url' => ['/site/logout'],],

                ['encode' => false,'label' => Html::submitButton('<i class="far fa-calendar-check"></i>Activity', ['style' => 'background-color: transparent; border: none; font-size: 15px;']), 'url' => ['/site/logout'],],

                ['encode' => false,'label' => Html::submitButton('<i class="far fa-question-circle"></i>FAQ', ['style' => 'background-color: transparent; border: none; font-size: 15px;']), 'url' => ['/site/logout'],],

                ['encode' => false,'label' => Html::submitButton('<i class="fas fa-sign-out-alt"></i>Sign Out', ['style' => 'background-color: transparent; border: none; font-size: 15px; color: white;'], ),

                'url' => ['/site/logout'],

                'linkOptions' => ['data-method' => 'post', 'style' => 'font-size: 15px; color: black;']],

                ]

                ];     

                }

        echo Nav::widget([

            'options' => ['class' => 'navbar-nav navbar-right'],

            'items' => $menuItems,

        ]);

        NavBar::end();

I would appreciate if you would give me an answer and explain it to me why is it like that.
Thank you in advance !!! :slight_smile:

Your construction of $menuItems is kinda chaotic, try to re-implement it step by step. I’ve pasted your $menuItems into my app and after deleting a typo inside, it worked. Try this clearer way:

$menuItems = [
            ['label' => 'Dropdown label', 'items' => [
                    ['label' => 'Label1', 'url' => ['/factory/index']],
                    ['label' => 'Label2', 'url' => ['/shift/index']]
            ]
      ]
];

thank you for your reply but it is still the same when you go to an error page it works but in my main page it dosent :slight_smile:

I don’t know how it works if theres a typo inside code you’ve posted (Sign Out line), unless code you are using is different.

its ok thanks again !!!.

1 Like