In the YUI 3 Gallery: Julien Lecomte's 1.3KB SimpleMenu with Keyboard and ARIA Support

By YUI TeamFebruary 12, 2010

Julien Lecomte wrote the SimpleMenu module for use on Yahoo! Search (the "More" link uses this code). It's superbly light — a 1.3KB minified script leveraging the YUI 3 core, plugin architecture, and keyboard/focus management utilities. Moreover, it's simple to use. He's shared it in the YUI 3 Gallery — you can use it under YUI's BSD license or you can grab the source from GitHub and use Julien's code as starting point for your own project.

Julien hasn't had time to document the widget fully, so I wrote up a common use case.

Take a simple piece of markup:

<!--menu activator-->
<a href="" id="optionsmenu">YUI-Related Links</a>

<!--menu contents-->
<div id="optionsmenucontainer" class="yui-cssreset">
<li><a href="">YUI documentation</a></li>
<li><a href="">YUI project site</a></li>
<li><a href="">YUI discussion forums</a></li>
<li><a href="/blog-archive">YUIBlog</a></li>
<li><a href="">YUI Theater</a></li>
<li><a href="">YUI 3 Gallery</a></li>
<li><a href="">@YUILibrary on Twitter</a></li>
<li><a href="">@YUILibrary developers on Twitter</a></li>

And the following script:

<script type="text/javascript" 

<script language="javascript">
YUI().use('gallery-simple-menu', function(Y) {'#optionsmenu').plug(Y.Plugin.SimpleMenu);

What remains is simply some CSS styling. Julien's widget applies the .menu-visible class when the menu is activated; a simple approach is to set the menu container's default position to absolute and move it off-screen. Then, in your .menu-visible declaration, remove the offset and allow the widget to position the container under its activator element:

#optionsmenucontainer {
} {

Click through to try this example in action.