Why is this dropdown not working in UIKit?

I am using UIKit to try to display an HTML list as a navbar. The navbar has several elements, some of which have nested children. I am trying to check that the WordPress theme I’m writing supports the WordPress unit tests.

See the GIF below:

Read More

Navbar GIF

As you can see, when I hover over Level 1, the dropdown correctly appears. If I move the cursor over Level 2 the dropdown closes instead of showing the contents of the Level 2 item. If I quickly move the cursor past the Level 2 item and onto either the Level 2A or Level 2B items (which do not have associated dropdown) the dropdown stays open.

Here is the HTML for the Level 1 li item:

<li class="uk-parent" data-uk-dropdown="" aria-haspopup="true" aria-expanded="false">
<a href="">Level 1 <i class="uk-icon-caret-down"></i></a>
<div class="uk-dropdown uk-dropdown-navbar" style="">
    <ul class="uk-nav uk-nav-dropdown">
        <li class="uk-parent" data-uk-dropdown="" aria-haspopup="true" aria-expanded="false">
            <a href="">Level 2 <i class="uk-icon-caret-down"></i></a>
            <div class="uk-dropdown uk-dropdown-navbar" style="">
                <ul class="uk-nav uk-nav-dropdown">
                    <li><a href="http://localhost/level-1/level-2/level-3/">Level 3</a></li>
                    <li><a href="http://localhost/level-1/level-2/level-3a/">Level 3a</a></li>
                    <li><a href="http://localhost/level-1/level-2/level-3b/">Level 3b</a></li>
                </ul>
            </div>
        </li>
        <li><a href="http://localhost/level-1/level-2a/">Level 2a</a></li>
        <li><a href="http://localhost/level-1/level-2b/">Level 2b</a></li>
    </ul>
</div>

The full navbar HTML is here (in case the problem is not with the Level 1 li):

<ul class="uk-navbar-nav">
<li><a href="http://wpthemetestdata.wordpress.com/">Home</a></li>
<li><a href="http://localhost/blog/">Blog</a></li>
<li><a href="http://localhost/front-page/">Front Page</a></li>
<li class="uk-parent" data-uk-dropdown="" aria-haspopup="true" aria-expanded="false">
    <a href="">About The Tests <i class="uk-icon-caret-down"></i></a>
        <div class="uk-dropdown uk-dropdown-navbar" style="">
            <ul class="uk-nav uk-nav-dropdown">
                <li><a href="http://localhost/about/page-image-alignment/">Page Image Alignment</a></li>
                <li><a href="http://localhost/about/page-markup-and-formatting/">Page Markup And Formatting</a></li>
                <li><a href="http://localhost/about/clearing-floats/">Clearing Floats</a></li>
                <li><a href="http://localhost/about/page-with-comments/">Page with comments</a></li>
                <li><a href="http://localhost/about/page-with-comments-disabled/">Page with comments disabled</a></li>
            </ul>
        </div>
    </li>
    <li class="uk-parent" data-uk-dropdown="" aria-haspopup="true" aria-expanded="false">
        <a href="">Level 1 <i class="uk-icon-caret-down"></i></a>
        <div class="uk-dropdown uk-dropdown-navbar" style="">
            <ul class="uk-nav uk-nav-dropdown">
                <li class="uk-parent" data-uk-dropdown="" aria-haspopup="true" aria-expanded="false">
                    <a href="">Level 2 <i class="uk-icon-caret-down"></i></a>
                    <div class="uk-dropdown uk-dropdown-navbar" style="">
                        <ul class="uk-nav uk-nav-dropdown">
                            <li><a href="http://localhost/level-1/level-2/level-3/">Level 3</a></li>
                            <li><a href="http://localhost/level-1/level-2/level-3a/">Level 3a</a></li>
                            <li><a href="http://localhost/level-1/level-2/level-3b/">Level 3b</a></li>
                        </ul>
                    </div>
                </li>
                <li><a href="http://localhost/level-1/level-2a/">Level 2a</a></li>
                <li><a href="http://localhost/level-1/level-2b/">Level 2b</a></li>
            </ul>
        </div>
    </li>
<li><a href="http://localhost/lorem-ipsum/">Lorem Ipsum</a></li>
<li><a href="http://localhost/page-a/">Page A</a></li>
<li><a href="http://localhost/page-b/">Page B</a></li>
</ul>

Is there an error in the HTML causing this?

Related posts

1 comment

  1. No, there isn’t an error in your HTML.

    I had the exact same problem last year and it seemed like it is was a known issue of UIKit 2.x. I’ve contacted the developers and they said that they will probably not fix this because they were already working on the next version – UIKit 3 – where this will not be an issue anymore.

    At the time I had to fix this somehow so I used a proxy attribute <div custom-dropdown></div> on the inner dropdown which I then used to select and initialize a regular uk-dropdown that I could control manually with the API. It looked something like:

    $("[custom-dropdown]").each(function(){
        var options = UIkit.Utils.options($(this).attr("custom-dropdown"));
        $(this).get(0).api = UIkit.dropdown($(this), options);
        ...
    });
    

    True to their words, one year later (currently at UIKit 3.0.0-rc.5) the bug is not present anymore.

    Here are a couple of fiddles to compare:

Comments are closed.