# SmartMenus Keyboard Addon

This is a demo of the SmartMenus jQuery Keyboard Addon which you can optionally include on your pages in addition to the SmartMenus jQuery plugin. It brings advanced keyboard navigation for all menu trees you may have on your pages.

By default without this addon the SmartMenus plugin includes basic keyboard navigation support - a user can use the `Tab` key to cycle through all main menu links, the `Enter` or `Space` key to activate the sub menus and also include their links in the tab order and the `Esc` key to deactivate the sub menus.

This addon takes keyboard navigation to a more advanced level by allowing the use of the keyboard `←` `→` `↑` `↓` arrow keys to browse the menu tree conveniently. Additionally a hotkey can be set too if needed - i.e. a keyboard shortcut that will send focus to any menu tree.

## Improving further accessibility

You can consider improving even further accessibility for users of screen readers or text mode browsers by wrapping the main menu item links in headings - e.g. on this demo page `<h2>` tags are used. This would allow such users to skip from branch to branch more easily in certain scenarios.

## Demo

Press `Shift` + `F12` to send focus to the first link in the main menu above (or press `Tab` as many times as need to focus some of the menu items). Then press `Enter`, `Space` or `↓` to activate some sub menu and then you can use the `←` `→` `↑` `↓` arrow keys to move the focus to other menu items. The script will automatically show/hide the sub menus as needed. You can press `Esc` at any time to deactivate the sub menus.

## Methods

This addon introduces the following API method:

keyboardSetHotkey
  Sets a hotkey combination that will send focus to the menu tree.
  Arguments:
  keyCode
    Type: Integer
    The key code for the hotkey (a good char code reference).
  modifiers
    Type: String, Array
    The hotkey modifier key. None, one or multiple of `'ctrlKey'`, `'shiftKey'`, `'altKey'`, `'metaKey'`.
  Code sample:

      // set Shift + F12 hotkey
          $('#main-menu').smartmenus('keyboardSetHotkey', 123, 'shiftKey');

          // set Ctrl + Alt + Shift + F12 hotkey
          $('#main-menu').smartmenus('keyboardSetHotkey', 123, ['ctrlKey', 'altKey', 'shiftKey']);

  Note: It is recommended to always use a combination (i.e. modifier + key) rather than use just a single key to avoid preventing important default browser features from working. `'shiftKey'` is best supported and probably the safest modifier you could use. `'ctrlKey'` and `'altKey'` generally work well too, there were just some issues with older Opera versions. `'metaKey'` is the Mac `⌘` key and it only works on Macs so, unless you know what you are doing, you probably shouldn't use it.

« Back to main demo