Skip to content
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

'nav' class should NOT be added in Init when Nav is used inside NavBar #212

Open
codermaverick opened this issue Aug 5, 2021 · 8 comments

Comments

@codermaverick
Copy link

Html::addCssClass($this->options, ['widget' => 'nav']);

The 'nav' class is always added in yii\bootstrap4\Nav's init method.
The documentation for yii\bootstrap4\NavBar indicates that yii\bootstrap4\Nav should be used between the begin() and end() calls of NavBar to create the menu, adding class 'navbar-nav'.

But, according to Bootstrap 4.6.x documentation, the 'ul' inside the NavBar should only have class 'navbar-nav', and NOT 'navbar-nav nav' as rendered by this widget.

https://getbootstrap.com/docs/4.6/components/navbar/#nav

@bizley
Copy link
Member

bizley commented Aug 5, 2021

Is this Nav or NavBar you are talking about?

@simialbi
Copy link
Contributor

simialbi commented Aug 5, 2021

Of course should it be added. See docs:
https://getbootstrap.com/docs/4.6/components/navs/
If you do not want the class to get added, Initialize Nav like this:

Nav::widget(['class' => ['widget' => '']]);

@codermaverick
Copy link
Author

The issue is with Nav, but it only presents when Nav is used inside a NavBar, as per yii\bootstrap4\NavBar documentation:
NavBar::begin();
echo Nav::widget([
'items' => [...],
'options' => ['class' => 'navbar-nav']
]);
NavBar::end();

As per Bootstrap 4 documentation, a standalone Nav must be of class 'nav' and optionally can have other classes, such as 'nav-pills'. This works ok in Yii2 when using standalone Navs.

According to BS 4 docs, the menu inside a NavBar must NOT have a 'nav' class, and should be of class 'navbar-nav' (+ plus optional utility classes).
In other words, BS4 does NOT use a Nav component inside NavBars, it uses a NavBar sub-component of class 'navbar-nav'.

Yii2's BS4 does NOT implement this correctly, since it recommends using a standard Nav component inside a NavBar.
And, since the 'nav' class is always added by Nav's init() method, the result does NOT exactly reflect BS4's implementation, and this could create problems when working with CSS or JS.

In summary, yii\bootstrap4\Nav should NOT have 'nav' class when used inside yii\bootstrap4\NavBar, or a different sub-component should be used to render navigation menus inside NavBars.

@codermaverick
Copy link
Author

@simialbi
Class 'nav' should NOT be added when creating a navigation menu inside a NavBar:
https://getbootstrap.com/docs/4.6/components/navbar/#nav
Note that the 'ul' is of class 'navbar-nav' and NOT 'navbar-nav nav' as rendered by yii\bootstrap4\Nav

@codermaverick
Copy link
Author

@simialbi
Nav::widget(['class' => ['widget' => '']]);
Did not work for me.
Class 'nav' is still being added to the 'ul'.

@simialbi
Copy link
Contributor

simialbi commented Aug 6, 2021

Hmmm... What about

Nav::widget(['class' => ['widget' => 'navbar-nav']]);

?

@bizley
Copy link
Member

bizley commented Aug 6, 2021

This won't work since Nav uses Html::addCssClass($this->options, ['widget' => 'nav']); in init.

@simialbi
Copy link
Contributor

simialbi commented Aug 6, 2021

According this test:
https://github.com/simialbi/yii2-bootstrap4/blob/master/tests/NavBarTest.php#L86

It works (namespaced class...):
https://github.com/simialbi/yii2-bootstrap4/actions/runs/1104198066

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants