dijit/_KeyNavContainer (version 1.10)

dijit/_FocusMixin, dijit/_KeyNavMixin, dijit/_Container

Summary

A _Container with keyboard navigation of its children.

Provides normalized keyboard and focusing code for Container widgets. To use this mixin, call connectKeyNavHandlers() in postCreate(). Also, child widgets must implement a focus() method.

See the dijit/_KeyNavContainer reference documentation for more information.

Property Summary

  • _focusManager
  • _keyNavCodesHash mapping key code (arrow keys and home/end key) to functions to handle those keys.
  • _searchString
  • focusedChildThe currently focused child widget, or null if there isn't one
  • multiCharSearchDurationIf multiple characters are typed where each keystroke happens within multiCharSearchDuration of the previous keystroke, search for nodes matching all the keystrokes.
  • tabIndexTab index of the container; same as HTML tabIndex attribute.

Method Summary

Event Summary

  • _onBlur(evt)
  • _onChildBlur(widget) Called when focus leaves a child widget to go to a sibling widget.
  • _onChildFocus(child) Called when a child widget gets focus, either by user clicking it, or programatically by arrow key handling code.
  • _onContainerFocus(evt) Handler for when the container itself gets focus.
  • _onContainerKeydown(evt) When a key is pressed, if it's an arrow key etc. then it's handled here.
  • _onContainerKeypress(evt) When a printable key is pressed, it's handled here, searching by letter.
  • _onDownArrow() Called on down arrow key.
  • _onFocus()
  • _onLeftArrow() Called on left arrow key, or right arrow key if widget is in RTL mode.
  • _onRightArrow() Called on right arrow key, or left arrow key if widget is in RTL mode.
  • _onUpArrow() Called on up arrow key.
  • onKeyboardSearch(item,evt,searchString,numMatches) When a key is pressed that matches a child item, this method is called so that a widget can take appropriate action is necessary.

Properties

_focusManager
Defined by: dijit/_FocusMixin
_keyNavCodes
Defined by: dijit/_KeyNavMixin

Hash mapping key code (arrow keys and home/end key) to functions to handle those keys. Usually not used directly, as subclasses can instead override _onLeftArrow() etc.

_searchString
Defined by: dijit/_KeyNavMixin
focusedChild
Defined by: dijit/_KeyNavMixin

The currently focused child widget, or null if there isn't one

multiCharSearchDuration
Defined by: dijit/_KeyNavMixin

If multiple characters are typed where each keystroke happens within multiCharSearchDuration of the previous keystroke, search for nodes matching all the keystrokes.

For example, typing "ab" will search for entries starting with "ab" unless the delay between "a" and "b" is greater than multiCharSearchDuration.

tabIndex
Defined by: dijit/_KeyNavMixin

Tab index of the container; same as HTML tabIndex attribute. Note then when user tabs into the container, focus is immediately moved to the first item in the container.

Methods

_getFirst()

Returns the first child.

Returns:null
_getFirstFocusableChild()
Defined by dijit/_KeyNavMixin

Returns first child that can be focused.

Returns:undefined
_getLast()

Returns the last descendant.

Returns:null
_getLastFocusableChild()
Defined by dijit/_KeyNavMixin

Returns last child that can be focused.

Returns:undefined
_getNext(child,dir)
Defined by dijit/_KeyNavMixin

Returns the next descendant, compared to "child".

Parameter Type Description
child Widget

The current widget

dir Integer
  • 1 = after
  • -1 = before
Returns:undefined | null
_getNextFocusableChild(child,dir)
Defined by dijit/_KeyNavMixin

Returns the next or previous focusable descendant, compared to "child". Implements and extends _KeyNavMixin._getNextFocusableChild() for a _Container.

Parameter Type Description
child Widget

The current widget

dir Integer
  • 1 = after
  • -1 = before
Returns:undefined | null
_getSiblingOfChild(child,dir)
Defined by dijit/_Container

Get the next or previous widget sibling of child

Parameter Type Description
child dijit/_WidgetBase
dir int

if 1, get the next sibling if -1, get the previous sibling

Returns:undefined
_keyboardSearch(evt,keyChar)
Defined by dijit/_KeyNavMixin

Perform a search of the widget's options based on the user's keyboard activity

Called on keypress (and sometimes keydown), searches through this widget's children looking for items that match the user's typed search string. Multiple characters typed within 1 sec of each other are combined for multicharacter searching.

Parameter Type Description
evt Event
keyChar String
_keyboardSearchCompare(item,searchString)
Defined by dijit/_KeyNavMixin

Compares the searchString to the widget's text label, returning:

* -1: a high priority match  and stop searching
* 0: not a match
* 1: a match but keep looking for a higher priority match
Parameter Type Description
item dijit/_WidgetBase
searchString String
Returns:number
_startupChild(widget)

Setup for each child widget.

Sets tabIndex=-1 on each child, so that the tab key will leave the container rather than visiting each child.

Note: if you add children by a different method than addChild(), then need to call this manually or at least make sure the child's tabIndex is -1.

Note: see also _LayoutWidget.setupChild(), which is also called for each child widget.

Parameter Type Description
widget dijit/_WidgetBase
addChild(widget,insertIndex)
Parameter Type Description
widget dijit/_WidgetBase
insertIndex int
Optional
buildRendering()
Defined by dijit/_Container
childSelector(node)
Parameter Type Description
node DOMNode
Returns:undefined
connectKeyNavHandlers(prevKeyCodes,nextKeyCodes)

Deprecated. You can call this in postCreate() to attach the keyboard handlers to the container, but the preferred method is to override _onLeftArrow() and _onRightArrow(), or _onUpArrow() and _onDownArrow(), to call focusPrev() and focusNext().

Parameter Type Description
prevKeyCodes dojo/keys

Key codes for navigating to the previous child.

nextKeyCodes dojo/keys

Key codes for navigating to the next child.

focus()
Defined by dijit/_KeyNavMixin

Default focus() implementation: focus the first child.

focusChild(widget,last)
Defined by dijit/_KeyNavMixin

Focus specified child widget.

Parameter Type Description
widget dijit/_WidgetBase

Reference to container's child widget

last Boolean

If true and if widget has multiple focusable nodes, focus the last one instead of the first one

focusFirstChild()
Defined by dijit/_KeyNavMixin

Focus the first focusable child in the container.

focusLastChild()
Defined by dijit/_KeyNavMixin

Focus the last focusable child in the container.

focusNext()

Focus the next widget

focusPrev()

Focus the last focusable node in the previous widget (ex: go to the ComboButton icon section rather than button section)

getIndexOfChild(child)
Defined by dijit/_Container

Gets the index of the child in this container or -1 if not found

Parameter Type Description
child dijit/_WidgetBase
Returns:undefined
hasChildren()
Defined by dijit/_Container

Returns true if widget has child widgets, i.e. if this.containerNode contains widgets.

Returns:boolean
postCreate()
Defined by dijit/_KeyNavMixin
removeChild(widget)
Defined by dijit/_Container

Removes the passed widget instance from this widget but does not destroy it. You can also pass in an integer indicating the index within the container to remove (ie, removeChild(5) removes the sixth widget).

Parameter Type Description
widget Widget | int
startup()
startupKeyNavChildren()

Events

_onBlur(evt)
Defined by: dijit/_KeyNavMixin
Parameter Type Description
evt undefined
_onChildBlur(widget)
Defined by: dijit/_KeyNavMixin

Called when focus leaves a child widget to go to a sibling widget. Used to be used by MenuBase.js (remove for 2.0)

Parameter Type Description
widget dijit/_WidgetBase
_onChildFocus(child)
Defined by: dijit/_KeyNavMixin

Called when a child widget gets focus, either by user clicking it, or programatically by arrow key handling code.

It marks that the current node is the selected one, and the previously selected node no longer is.

Parameter Type Description
child dijit/_WidgetBase
_onContainerFocus(evt)
Defined by: dijit/_KeyNavMixin

Handler for when the container itself gets focus.

Initially the container itself has a tabIndex, but when it gets focus, switch focus to first child.

TODO for 2.0 (or earlier): Instead of having the container tabbable, always maintain a single child widget as tabbable, Requires code in startup(), addChild(), and removeChild(). That would avoid various issues like #17347.

Parameter Type Description
evt undefined
_onContainerKeydown(evt)
Defined by: dijit/_KeyNavMixin

When a key is pressed, if it's an arrow key etc. then it's handled here.

Parameter Type Description
evt undefined
_onContainerKeypress(evt)
Defined by: dijit/_KeyNavMixin

When a printable key is pressed, it's handled here, searching by letter.

Parameter Type Description
evt undefined
_onDownArrow()
Defined by: dijit/_KeyNavMixin

Called on down arrow key. Should go to the next child in vertical container widgets like Menu.

_onFocus()
Defined by: dijit/_KeyNavMixin
_onLeftArrow()
Defined by: dijit/_KeyNavMixin

Called on left arrow key, or right arrow key if widget is in RTL mode. Should go back to the previous child in horizontal container widgets like Toolbar.

_onRightArrow()
Defined by: dijit/_KeyNavMixin

Called on right arrow key, or left arrow key if widget is in RTL mode. Should go to the next child in horizontal container widgets like Toolbar.

_onUpArrow()
Defined by: dijit/_KeyNavMixin

Called on up arrow key. Should go to the previous child in vertical container widgets like Menu.

onKeyboardSearch(item,evt,searchString,numMatches)
Defined by: dijit/_KeyNavMixin

When a key is pressed that matches a child item, this method is called so that a widget can take appropriate action is necessary.

Parameter Type Description
item dijit/_WidgetBase
evt Event
searchString String
numMatches Number
Error in the documentation? Can’t find what you are looking for? Let us know!