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

February 12, 2010 at 9:21 am by Eric Miraglia | In YUI 3 Gallery | 6 Comments

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="http://developer.yahoo.com/yui/" id="optionsmenu">YUI-Related Links</a>

<!--menu contents-->
<div id="optionsmenucontainer" class="yui-cssreset">
<ul>
<li><a href="http://developer.yahoo.com/yui/">YUI documentation</a></li>
<li><a href="http://yuilibrary.com">YUI project site</a></li>
<li><a href="http://yuilibrary.com/forum/">YUI discussion forums</a></li>
<li><a href="http://yuiblog.com">YUIBlog</a></li>
<li><a href="http://developer.yahoo.com/yui/theater/">YUI Theater</a></li>
<li><a href="http://yuilibrary.com/gallery/">YUI 3 Gallery</a></li>
<li><a href="http://twitter.com/yuilibrary">@YUILibrary on Twitter</a></li>
<li><a href="http://twitter.com/miraglia/yui/members">@YUILibrary developers on Twitter</a></li>
</ul>
</div>

And the following script:

<script type="text/javascript" 
src="http://yui.yahooapis.com/combo?3.0.0/build/yui/yui-min.js&gallery-2010.02.10-01/
build/gallery-simple-menu/gallery-simple-menu-min.js"></script>

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

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 {
    left:-4500px;
    position:absolute;
}

#optionsmenucontainer.menu-visible {
    left:auto;
}

Click through to try this example in action.

Share and extend: Bookmark with del.icio.us | digg it! | reddit!

6 Comments »

RSS feed for comments on this post. TrackBack URI

  1. Does it support sub-menus?

    Comment by figvam — February 12, 2010 #

  2. No, this is a simple, one-level menu, really geared to this simplest use case.

    You may be interested in NodeMenuNav — http://developer.yahoo.com/yui/3/examples/node-menunav/node-menunav-1.html

    -Eric

    Comment by Eric Miraglia — February 12, 2010 #

  3. [...] YUIのドロップダウンメニューにて、キーボードでのフォーカスに対応させる事が可能になったようです。SimpleMenu module というモジュールでYahooでの検索に使用するために作られたようです。 [...]

    Pingback by キーボードに対応したドロップダウンメニューを作れるYUIのモジュール「SimpleMenu」 | Web活メモ帳 — February 12, 2010 #

  4. [...] 3 Gallery is transitional solutions that help flesh out YUI 3 implementations. Some of these, like Julien Lecomte’s SimpleMenu, are pure YUI 3, and others, like Adam Moore’s TreeView module, help bridge the gap between [...]

    Pingback by In the YUI 3 Gallery: Adam Moore’s YUI TreeView Port » Yahoo! User Interface Blog (YUIBlog) — February 18, 2010 #

  5. [...] an exciting couple of weeks in the YUI community with some great new gallery modules (Storage Lite, Simple Menu, and more good ones coming). Here’s some other recent news, featuring two nice YUI demos from [...]

    Pingback by In the Wild for February 26, 2010 » Yahoo! User Interface Blog (YUIBlog) — February 26, 2010 #

  6. [...] Grove’s excellent Storage and History modules, Ilyan Peychev’s über-popular Accordion, Julien Lecomte’s SimpleMenu, Stephen Woods’s Timepicker, Adam Moore’s TreeView, Jeff Craig’s Chromahash, [...]

    Pingback by YUI 3 Gallery Contest 2010 — Win a Ticket to JSConf 2010 » Yahoo! User Interface Blog (YUIBlog) — March 5, 2010 #

Leave a comment

Note: Comments are moderated for first-timers. Spam deleted.

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Hosted by Yahoo!

Copyright © 2006-2010 Yahoo! Inc. All rights reserved. Privacy Policy - Terms of Service

Powered by WordPress on Yahoo! Web Hosting.