dijit/_KeyNavMixin (version 1.10)

dijit/_FocusMixin

Summary

A mixin to allow arrow key and letter key navigation of child or descendant widgets. It can be used by dijit/_Container based widgets with a flat list of children, or more complex widgets like dijit/Tree.

To use this mixin, the subclass must:

- Implement  _getNext(), _getFirst(), _getLast(), _onLeftArrow(), _onRightArrow()
  _onDownArrow(), _onUpArrow() methods to handle home/end/left/right/up/down keystrokes.
  Next and previous in this context refer to a linear ordering of the descendants used
  by letter key search.
- Set all descendants' initial tabIndex to "-1"; both initial descendants and any
  descendants added later, by for example addChild()
- Define childSelector to a function or string that identifies focusable descendant widgets

Also, child widgets must implement a focus() method.

See the dijit/_KeyNavMixin 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
  • childSelectorSelector (passed to on.selector()) used to identify what to treat as a child widget.
  • 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

  • _getFirst() Returns the first child.
  • _getFirstFocusableChild() Returns first child that can be focused.
  • _getLast() Returns the last descendant.
  • _getLastFocusableChild() Returns last child that can be focused.
  • _getNext(child,dir) Returns the next descendant, compared to "child".
  • _getNextFocusableChild(child,dir) Returns the next or previous focusable descendant, compared to "child".
  • _keyboardSearch(evt,keyChar) Perform a search of the widget's options based on the user's keyboard activity
  • _keyboardSearchCompare(item,searchString) 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
  • focus() Default focus() implementation: focus the first child.
  • focusChild(widget,last) Focus specified child widget.
  • focusFirstChild() Focus the first focusable child in the container.
  • focusLastChild() Focus the last focusable child in the container.
  • postCreate()

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
childSelector
Defined by: dijit/_KeyNavMixin

Selector (passed to on.selector()) used to identify what to treat as a child widget. Used to monitor focus events and set this.focusedChild. Must be set by implementing class. If this is a string (ex: "> *") then the implementing class must require dojo/query.

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()
Defined by dijit/_KeyNavMixin

Returns the first child.

Returns:null
_getFirstFocusableChild()
Defined by dijit/_KeyNavMixin

Returns first child that can be focused.

Returns:undefined
_getLast()
Defined by dijit/_KeyNavMixin

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
_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
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.

postCreate()
Defined by dijit/_KeyNavMixin

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!