Options
All
  • Public
  • Public/Protected
  • All
Menu

Class FocusTracker<T>

A class which tracks focus among a set of widgets. The namespace for the FocusTracker class statics.

This class is useful when code needs to keep track of the most recently focused widget(s) among a set of related widgets.

Type parameters

Hierarchy

  • FocusTracker

Implements

  • IDisposable

Index

Constructors

constructor

Properties

Private _activeChanged

_activeChanged: Signal<this, IChangedArgs<T>> = new Signal<this, FocusTracker.IChangedArgs<T>>(this)

Private _activeWidget

_activeWidget: T | null = null

Private _counter

_counter: number = 0

Private _currentChanged

_currentChanged: Signal<this, IChangedArgs<T>> = new Signal<this, FocusTracker.IChangedArgs<T>>(this)

Private _currentWidget

_currentWidget: T | null = null

Private _nodes

_nodes: Map<HTMLElement, T> = new Map<HTMLElement, T>()

Private _numbers

_numbers: Map<T, number> = new Map<T, number>()

Private _widgets

_widgets: T[] = []

Accessors

activeChanged

activeWidget

  • get activeWidget(): T | null
  • The active widget in the tracker.

    Notes

    The active widget is the widget among the tracked widgets which has the descendant node which is currently focused.

    Returns T | null

currentChanged

currentWidget

  • get currentWidget(): T | null
  • The current widget in the tracker.

    Notes

    The current widget is the widget among the tracked widgets which has the descendant node which has most recently been focused.

    The current widget will not be updated if the node loses focus. It will only be updated when a different tracked widget gains focus.

    If the current widget is removed from the tracker, the previous current widget will be restored.

    This behavior is intended to follow a user's conceptual model of a semantically "current" widget, where the "last thing of type X" to be interacted with is the "current instance of X", regardless of whether that instance still has focus.

    Returns T | null

isDisposed

  • get isDisposed(): boolean
  • A flag indicating whether the tracker is disposed.

    Returns boolean

widgets

  • get widgets(): ReadonlyArray<T>
  • A read only array of the widgets being tracked.

    Returns ReadonlyArray<T>

Methods

Private _evtBlur

  • _evtBlur(event: FocusEvent): void
  • Handle the 'blur' event for a tracked widget.

    Parameters

    • event: FocusEvent

    Returns void

Private _evtFocus

  • _evtFocus(event: FocusEvent): void
  • Handle the 'focus' event for a tracked widget.

    Parameters

    • event: FocusEvent

    Returns void

Private _onWidgetDisposed

  • _onWidgetDisposed(sender: T): void
  • Handle the disposed signal for a tracked widget.

    Parameters

    • sender: T

    Returns void

Private _setWidgets

  • _setWidgets(current: T | null, active: T | null): void
  • Set the current and active widgets for the tracker.

    Parameters

    • current: T | null
    • active: T | null

    Returns void

add

  • add(widget: T): void
  • Add a widget to the focus tracker.

    Parameters

    • widget: T

      The widget of interest.

      Notes

      A widget will be automatically removed from the tracker if it is disposed after being added.

      If the widget is already tracked, this is a no-op.

    Returns void

dispose

  • dispose(): void
  • Dispose of the resources held by the tracker.

    Returns void

focusNumber

  • focusNumber(widget: T): number
  • Get the focus number for a particular widget in the tracker.

    Parameters

    • widget: T

      The widget of interest.

    Returns number

    The focus number for the given widget, or -1 if the widget has not had focus since being added to the tracker, or is not contained by the tracker.

    Notes

    The focus number indicates the relative order in which the widgets have gained focus. A widget with a larger number has gained focus more recently than a widget with a smaller number.

    The currentWidget will always have the largest focus number.

    All widgets start with a focus number of -1, which indicates that the widget has not been focused since being added to the tracker.

handleEvent

  • handleEvent(event: Event): void
  • Handle the DOM events for the focus tracker.

    Parameters

    • event: Event

      The DOM event sent to the panel.

      Notes

      This method implements the DOM EventListener interface and is called in response to events on the tracked nodes. It should not be called directly by user code.

    Returns void

has

  • has(widget: T): boolean
  • Test whether the focus tracker contains a given widget.

    Parameters

    • widget: T

      The widget of interest.

    Returns boolean

    true if the widget is tracked, false otherwise.

remove

  • remove(widget: T): void
  • Remove a widget from the focus tracker.

    Notes

    If the widget is the currentWidget, the previous current widget will become the new currentWidget.

    A widget will be automatically removed from the tracker if it is disposed after being added.

    If the widget is not tracked, this is a no-op.

    Parameters

    • widget: T

    Returns void

Generated using TypeDoc