FocusCycler (ui)
@ckeditor/ckeditor5-ui/src/focuscycler
A utility class that helps cycling over focusable views in a
ViewCollection
when the focus is tracked by the
FocusTracker
instance. It helps implementing keyboard
navigation in HTML forms, toolbars, lists and the like.
To work properly it requires:
- a collection of focusable (HTML
tabindex
attribute) views that implement thefocus()
method, - an associated focus tracker to determine which view is focused.
A simple cycler setup can look like this:
Then, the cycler can be used manually:
Alternatively, it can work side by side with the KeystrokeHandler
:
Check out the "Deep dive into focus tracking" guide to learn more.
Filtering
Properties
-
actions : Object
readonly
Actions that the cycler can take when a keystroke is pressed. Requires
options.keystrokeHandler
to be passed and working. When an action is performed,preventDefault
andstopPropagation
will be called on the event the keystroke fired in the DOM. -
current : Number | null
readonly
An index of the view in the
focusables
which is focused according tofocusTracker
. Returnsnull
when there is no such view. -
Returns the first focusable view in
focusables
. Returnsnull
if there is none.Note: Hidden views (e.g. with
display: none
) are ignored. -
focusTracker : FocusTracker
readonly
A focus tracker instance that the cycler uses to determine the current focus state in
focusables
. -
focusables : Collection
readonly
A view collection that the cycler operates on.
-
keystrokeHandler : KeystrokeHandler
readonly
An instance of the
KeystrokeHandler
which can respond to certain keystrokes and cycle the focus. -
Returns the last focusable view in
focusables
. Returnsnull
if there is none.Note: Hidden views (e.g. with
display: none
) are ignored. -
Returns the next focusable view in
focusables
based oncurrent
. Returnsnull
if there is none.Note: Hidden views (e.g. with
display: none
) are ignored. -
Returns the previous focusable view in
focusables
based oncurrent
. Returnsnull
if there is none.Note: Hidden views (e.g. with
display: none
) are ignored.
Methods
-
constructor( options = { options.focusables, options.focusTracker, [options.keystrokeHandler], [options.actions] } )
Creates an instance of the focus cycler utility.
Parameters
options : Object
Configuration options.
Propertiesoptions.focusables : Collection | Object
options.focusTracker : FocusTracker
[ options.keystrokeHandler ] : KeystrokeHandler
[ options.actions ] : Object
-
Focuses the
first
item infocusables
.Note: Hidden views (e.g. with
display: none
) are ignored. -
Focuses the
last
item infocusables
.Note: Hidden views (e.g. with
display: none
) are ignored. -
Focuses the
next
item infocusables
.Note: Hidden views (e.g. with
display: none
) are ignored. -
Focuses the
previous
item infocusables
.Note: Hidden views (e.g. with
display: none
) are ignored. -
_focus( view )
protected
Focuses the given view if it exists.
Parameters
view : View
-
_getFocusableItem( step ) → View | null
protected
Returns the next or previous focusable view in
focusables
with respect tocurrent
.
Every day, we work hard to keep our documentation complete. Have you spotted an outdated information? Is something missing? Please report it via our issue tracker.