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(event: KeyboardEvent): boolean: {}

Callback to be executed for a specified input.

public

whenCallback(event: KeyboardEvent): boolean: *

Callback that determines whether keyboard input should be handled.

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

onCancel(callback: KeyboardNavigatable~keyCallback): KeyboardNavigatable

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

public

onDown(callback: KeyboardNavigatable~keyCallback): KeyboardNavigatable

Provide a callback to be executed when navigating downwards.

public

onRemove(callback: KeyboardNavigatable~keyCallback): KeyboardNavigatable

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

public

onSelect(callback: KeyboardNavigatable~keyCallback): KeyboardNavigatable

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

public

onUp(callback: KeyboardNavigatable~keyCallback): KeyboardNavigatable

Provide a callback to be executed when navigating upwards.

public

when(callback: KeyboardNavigatable~whenCallback): KeyboardNavigatable

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

Public Constructors

public constructor() source

Public Members

public callbacks(event: KeyboardEvent): boolean: {} source

Callback to be executed for a specified input.

Return:

boolean

public whenCallback(event: KeyboardEvent): boolean: * source

Callback that determines whether keyboard input should be handled. By default, always handle keyboard navigation.

Return:

boolean

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: KeyboardNavigatable~keyCallback): KeyboardNavigatable source

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

This will be triggered by the Escape key.

Params:

NameTypeAttributeDescription
callback KeyboardNavigatable~keyCallback

public onDown(callback: KeyboardNavigatable~keyCallback): KeyboardNavigatable source

Provide a callback to be executed when navigating downwards.

This will be triggered by the Down key.

Params:

NameTypeAttributeDescription
callback KeyboardNavigatable~keyCallback

public onRemove(callback: KeyboardNavigatable~keyCallback): KeyboardNavigatable source

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

This will be triggered by the Backspace key.

Params:

NameTypeAttributeDescription
callback KeyboardNavigatable~keyCallback

public onSelect(callback: KeyboardNavigatable~keyCallback): 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 KeyboardNavigatable~keyCallback

public onUp(callback: KeyboardNavigatable~keyCallback): KeyboardNavigatable source

Provide a callback to be executed when navigating upwards.

This will be triggered by the Up key.

Params:

NameTypeAttributeDescription
callback KeyboardNavigatable~keyCallback

public when(callback: KeyboardNavigatable~whenCallback): KeyboardNavigatable source

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

Params:

NameTypeAttributeDescription
callback KeyboardNavigatable~whenCallback