Reference Source
import KeyboardNavigatable from 'flarum/utils/KeyboardNavigatable'
public class | source

KeyboardNavigatable

The KeyboardNavigatable class manages lists that can be navigated with the keyboard, calling callbacks for each actions.

This helper encapsulates the key binding logic, providing a simple fluent API for use.

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

callbacks: {}

public

Method Summary

Public Methods
public

bindTo($element: jQuery)

Set up the navigation key bindings on the given jQuery element.

public

navigate(event: KeyboardEvent)

Interpret the given keyboard event as navigation commands.

public

Provide a callback to be executed when the navigation is canceled.

public

Provide a callback to be executed when navigating downwards.

public

Provide a callback to be executed when previous input is removed.

public

Provide a callback to be executed when the current item is selected..

public

Provide a callback to be executed when navigating upwards.

public

Provide a callback that determines whether keyboard input should be handled.

Public Constructors

public constructor() source

Public Members

public callbacks: {} source

public whenCallback: * source

Public Methods

public bindTo($element: jQuery) source

Set up the navigation key bindings on the given jQuery element.

Params:

NameTypeAttributeDescription
$element jQuery

public navigate(event: KeyboardEvent) source

Interpret the given keyboard event as navigation commands.

Params:

NameTypeAttributeDescription
event KeyboardEvent

public onCancel(callback: Function): KeyboardNavigatable source

Provide a callback to be executed when the navigation is canceled.

This will be triggered by the Escape key.

Params:

NameTypeAttributeDescription
callback Function

public onDown(callback: Function): KeyboardNavigatable source

Provide a callback to be executed when navigating downwards.

This will be triggered by the Down key.

Params:

NameTypeAttributeDescription
callback Function

public onRemove(callback: Function): KeyboardNavigatable source

Provide a callback to be executed when previous input is removed.

This will be triggered by the Backspace key.

Params:

NameTypeAttributeDescription
callback Function

public onSelect(callback: Function): KeyboardNavigatable source

Provide a callback to be executed when the current item is selected..

This will be triggered by the Return and Tab keys..

Params:

NameTypeAttributeDescription
callback Function

public onUp(callback: Function): KeyboardNavigatable source

Provide a callback to be executed when navigating upwards.

This will be triggered by the Up key.

Params:

NameTypeAttributeDescription
callback Function

public when(callback: Function): KeyboardNavigatable source

Provide a callback that determines whether keyboard input should be handled.

Params:

NameTypeAttributeDescription
callback Function