Examples that utilize Menu
and MenuButton
components with ARIA and keyboard support.
- Calls to
setFocusToButton
are made independently of, and prior to, calls to theclose
method. - Code in
keydown
handler forSPACE/RETURN
relies on the click handlerhandleClick
to call thesetFocusToButton
andclose
methods in order to avoid duplication of method calls. - Renamed
previousItem
andnextItem
tosetFocusToPreviousItem
andsetFocusToNextItem
to show their relationship to othersetFocus
methods.
- The property
isLink
(see constructor) is unused: what was its original purpose? - In the
keydown
handler, removed handling forTAB
, which does not appear to need special handling. - Removed
focus
andblur
event handling, which appears to be unneeded for the button. - Eliminated
openMenu
andcloseMenu
methods; replaced with calls toMenu
methodsopen
andclose
. - Renamed methods
moveFocusToFirstMenuItem
andmoveFocusToLastMenuItem
tosetFocusToFirstItem
andsetFocusToLastItem
respectively, and moved them to theMenu
object.
- If you set
display: none
on an element and that element or one of its contained descendants has focus, when the element and/or its descendants become no longer visible, the browser will, by default, set focus to the first focusable element on the page. To avoid this, set the focus to its target destination (if one exists) before settingdisplay: none
.
- Use
var that = this;
whenever alternatethis
reference is needed. - Comments: use blank line as separator, indent four spaces,
@param
name on separate lines
Menu
: handlemouseover
andmouseout
formenuNode
elementMenuButton
: handlemouseover
andmouseout
forbuttonNode
element
Menu
: handlekeydown
:SPACE/RETURN
,ESC
,UP
,DOWN
,HOME/PAGEUP
,END/PAGEDOWN
,TAB
for menu item elementsMenuButton
: handlekeydown
:SPACE/RETURN
,UP
,DOWN
forbuttonNode
element
Menu
: handlefocus
andblur
for menu item elements
Menu
: explicit calls tobuttonNode.focus()
before closing menuMenuButton
: explicit calls to menu itemsetFocus
methods