wp-bootstrap-navwalker icon indicating copy to clipboard operation
wp-bootstrap-navwalker copied to clipboard

dropdown-divider class is duplicated

Open gillespieza opened this issue 6 years ago • 10 comments

When I run my rendered HTML source code through a validator, it shows that items with the class "dropdown-divider" are getting the class added twice.

Here is an example of my output: <li itemscope="itemscope" itemtype="https://www.schema.org/SiteNavigationElement" id="menu-item-6731" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-6731 nav-item"><div class="dropdown-divider" title="----" class="dropdown-item dropdown-divider">/</div></li>

The last div is getting class="dropdown-divider" and class="dropdown-item dropdown-divider"

gillespieza avatar May 01 '18 17:05 gillespieza

Hey @gillespieza,

Thanks for reporting this. I'll take a look either tonight or tomorrow and see where I need to fix this :)

pattonwebz avatar May 01 '18 18:05 pattonwebz

Hey, sorry for delays. I am not able to reproduce this output. I'm getting:

<li itemscope="itemscope" itemtype="https://www.schema.org/SiteNavigationElement" id="menu-item-1707" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1707 nav-item"><div class="dropdown-divider" title="a divider">a divider</div></li>

Are you using the latest version of the walker? Are my settings the same as yours? screenshot from 2018-05-27 16-33-03

pattonwebz avatar May 27 '18 15:05 pattonwebz

I wasn't using the latest version. My apologies. Once I updated, the issue went away.

gillespieza avatar May 28 '18 10:05 gillespieza

No apologies necessary, glad you got it fixed :)

pattonwebz avatar May 28 '18 10:05 pattonwebz

I am using the latest version 4.1.0 (just redownloaded again from https://github.com/wp-bootstrap/wp-bootstrap-navwalker/blob/master/class-wp-bootstrap-navwalker.php) and have the same problem.

I embedded the menu with the following code:

<?php wp_nav_menu(array(
    'theme_location' => 'primary',
    'depth' => 0,
    'container' => 'div',
    'container_class'=>'collapse navbar-collapse',
    'container_id'=> 'nav-primary',
    'menu_class'=>'navbar-nav ml-auto',
    'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
    'walker' => new WP_Bootstrap_Navwalker(),
)); ?>

Adding a sub-menu item with

  • class "dropdown-divider"
  • title "-"
  • link "#"

results in the following item

<li itemscope="itemscope" itemtype="https://www.schema.org/SiteNavigationElement" id="menu-item-5434" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-5434 nav-item"><div class="dropdown-divider" title="-" class="dropdown-item dropdown-divider">&#8211;</div></li>

As you can see the class is inserted twice

  • class="dropdown-divider"
  • class="dropdown-item dropdown-divider"

lanort avatar Mar 13 '19 14:03 lanort

Hey @lanort,

Sorry you are having issues. I can see in your markup that it is duplicated but in my test install it is not and I am not able to recreate this with the latest version from master branch. Screenshot from 2019-03-13 18-48-59

The markup that I end up with is:

<li itemscope="itemscope" itemtype="https://www.schema.org/SiteNavigationElement" id="menu-item-1727" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1727 nav-item"><div class="dropdown-divider" title="–">–</div></li>

Is there anything else at all you think might be relevant to help me recreate this issue and fix it?

pattonwebz avatar Mar 13 '19 18:03 pattonwebz

Thanks @pattonwebz.

Is this the actual source code or already the interpreted one? I think in my browser also only the first class counts and the second one is ignored (this would end up the same as in your result).

However I will check that on another website of mine tomorrow, just to make sure I or another plugin did not mess up anything.

lanort avatar Mar 13 '19 21:03 lanort

You make a good point, this is likely generated markup. I will check actual source as soon as I am able.

I reopened the ticket since you confirmed this is still an issue. I might have spotted a potential fix for it earlier when scanning the code in my test install.

Let me know what you see in your end, I'll be sure to check proper source on my end as well.

pattonwebz avatar Mar 13 '19 21:03 pattonwebz

Just tried the current version on another website and it had the same result: <li itemscope="itemscope" itemtype="https://www.schema.org/SiteNavigationElement" id="menu-item-1651" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1651 nav-item"><div class="dropdown-divider" title="-" class="dropdown-item dropdown-divider">&#8211;</div></li>

You can see it here http://neu.derzahn.at

The dropdown-divider was inserted with this data: Menu

The interpreted code has the double class already stripped (but the source code of course still has the double class): Interpreted code

<li itemscope="itemscope" itemtype="https://www.schema.org/SiteNavigationElement" id="menu-item-1651" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1651 nav-item"><div class="dropdown-divider" title="-">–</div></li>

lanort avatar Mar 14 '19 12:03 lanort

Note: this is still a bug.

The class dropdown-divider is added here https://github.com/wp-bootstrap/wp-bootstrap-navwalker/blob/c856e941c4209581f8b90a31cc33350c758b3cfb/class-wp-bootstrap-navwalker.php#L502-L504 and here https://github.com/wp-bootstrap/wp-bootstrap-navwalker/blob/c856e941c4209581f8b90a31cc33350c758b3cfb/class-wp-bootstrap-navwalker.php#L556-L558 This is also the case for dropdown-header and dropdown-item-text.

IanDelMar avatar Jan 30 '21 22:01 IanDelMar