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

Callback to be executed for a specified input.

public

whenCallback: ShouldHandle

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: KeyboardEventHandler): KeyboardNavigatable

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

public

onDown(callback: KeyboardEventHandler): KeyboardNavigatable

Provide a callback to be executed when navigating downwards.

public

onRemove(callback: KeyboardEventHandler): KeyboardNavigatable

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

public

onSelect(callback: KeyboardEventHandler): KeyboardNavigatable

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

public

onUp(callback: KeyboardEventHandler): KeyboardNavigatable

Provide a callback to be executed when navigating upwards.

public

when(callback: ShouldHandle): KeyboardNavigatable

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

Public Constructors

public constructor() source

Public Members

public callbacks: * source

Callback to be executed for a specified input.

public whenCallback: ShouldHandle source

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

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

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

This will be triggered by the Escape key.

Params:

NameTypeAttributeDescription
callback KeyboardEventHandler

public onDown(callback: KeyboardEventHandler): KeyboardNavigatable source

Provide a callback to be executed when navigating downwards.

This will be triggered by the Down key.

Params:

NameTypeAttributeDescription
callback KeyboardEventHandler

public onRemove(callback: KeyboardEventHandler): KeyboardNavigatable source

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

This will be triggered by the Backspace key.

Params:

NameTypeAttributeDescription
callback KeyboardEventHandler

public onSelect(callback: KeyboardEventHandler): 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 KeyboardEventHandler

public onUp(callback: KeyboardEventHandler): KeyboardNavigatable source

Provide a callback to be executed when navigating upwards.

This will be triggered by the Up key.

Params:

NameTypeAttributeDescription
callback KeyboardEventHandler

public when(callback: ShouldHandle): KeyboardNavigatable source

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

Params:

NameTypeAttributeDescription
callback ShouldHandle