Class DOMKeyboardDriver

A KeyboardDriver which listens for key events from HTML DOM elements.

Note that if a DOM element is unfocused in the DOM to an unbound DOM element, the root focus is cleared. If this creates issues, other DOM elements can be bound without listening for key events.

Hierarchy

Constructors

Properties

domElems: Map<HTMLElement, DOMKeyboardDriverBind> = ...

The list of HTML DOM elements bound to this keyboard driver and their event listeners

Accessors

  • get needsInput(): boolean
  • Check if the currently focused root needs keyboard input. Virtual keyboard should query this property to know when to show themselves.

    Returns boolean

Methods

  • Bind an HTML DOM element to this keyboard driver.

    If the root was already bound, removeListeners is called, replacing the old listeners. Populates domElems with the new bind.

    Parameters

    • domElem: HTMLElement
    • listenToKeys: boolean = true

      If true, event listeners will be added to listen for keys. blur event listeners are always added no matter what.

    Returns void

  • Calls preventDefault on a keyboard event if needed.

    Parameters

    • event: KeyboardEvent

    Returns void

  • Does nothing if the new focus type is not a Keyboard. If the focus comes from a root which is not the root focus, then the root focus is changed to the new root. If there is no new focused widget (the root's keyboard focus was cleared), then nothing happens.

    This behaviour is confusing, however, it's required so that the keyboard focus "lingers" for future tab key presses; this way, pressing tab can do tab selection even when there is no widget that wants keyboard input. When a focus is lingering, then it means that key events are still being dispatched to the last focused root, but they don't have a target. This way, most events get dropped, but tab key events are used for tab selection.

    Parameters

    Returns void

  • Check if the root focus should be cleared given that the HTML DOM focus has been lost to another HTML DOM element

    Parameters

    • newTarget: null | HTMLElement

      The HTML DOM element to which the focus has been lost to

    Returns boolean

  • Unbind an HTML DOM element from this keyboard driver. Removes all used listeners.

    Parameters

    • domElem: HTMLElement

    Returns void

Generated using TypeDoc