Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SelectionEventsHelper

Helper class that can be used by application-defined UI components for handling keyboard and mouse interaction with component.

Implements selection model that is similar to Excel or Google Sheets. Concrete handled patterns you can see in concrete methods documentation.

This implementation doesn't use any browser specific objects such as events and doesn't use any browser API.

Hierarchy

  • SelectionEventsHelper

Index

Constructors

constructor

Properties

horizontal

horizontal: boolean

true for shifting to next/previous item in list of items by Left Arrow/Right Arrow keys instead of Arrow Up/Arrow Down keys.

multiple

multiple: boolean

true to make possible to pick several items in list of items (by clicking range of items with pressed Shift key, for example).

selectionService

selectionService: SelectionService

Any implementation of SelectionService to perform actual selection.

see

DefaultSelectionService

toggleOnly

toggleOnly: boolean

If true, then next item selection doesn't clear selection of previously selected items. The only way to clean selection is second click on previously selected element. This can be used to implement accordion-like behavior in application-defined UI component.

Methods

keyboardHandler

  • keyboardHandler(ctrlKeyPressed: boolean, shiftKeyPressed: boolean, keyCode: KeyCodes): boolean

mouseHandler

  • mouseHandler(ctrlKeyPressed: boolean, shiftKeyPressed: boolean, mouseButton: MouseButtons, itemIndex: number): boolean
  • Common handler for mouse events.

    Parameters

    • ctrlKeyPressed: boolean

      true if Ctrl key was pressed.

    • shiftKeyPressed: boolean

      true if Shift key was pressed.

    • mouseButton: MouseButtons

      specifies which mouse button was pressed.

    • itemIndex: number

      index of clicked element in SelectionService.items collection.

    Returns boolean

    true if any of executed commands was applied.

Protected onNextKey

  • onNextKey(ctrlKeyPressed: boolean, shiftKeyPressed: boolean): boolean
  • Common handler for Arrow Down key (Arrow Right if {@link SelectionAreaConfig.horizontal} is true). Calls applicable handlers one by one until any returns true.

    Parameters

    • ctrlKeyPressed: boolean

      true if Ctrl key was pressed.

    • shiftKeyPressed: boolean

      true if Shift key was pressed.

    Returns boolean

    true if any of executed commands was applied.

Protected onPreviousKey

  • onPreviousKey(ctrlKeyPressed: boolean, shiftKeyPressed: boolean): boolean
  • Common handler for Arrow Up key (Arrow Left if {@link SelectionAreaConfig.horizontal} is true). Calls applicable handlers one by one until any returns true.

    Parameters

    • ctrlKeyPressed: boolean

      true if Ctrl key was pressed.

    • shiftKeyPressed: boolean

      true if Shift key was pressed.

    Returns boolean

    true if any of executed commands was applied.

Protected tryBuildRangeWithNextItemWhenLastItemWasDeselected

  • tryBuildRangeWithNextItemWhenLastItemWasDeselected(ctrlKeyPressed: boolean, shiftKeyPressed: boolean): boolean
  • Tries to select element that is next to the last processed element and last processed element was deselected.

    Parameters

    • ctrlKeyPressed: boolean

      true if Ctrl key was pressed.

    • shiftKeyPressed: boolean

      true if Shift key was pressed.

    Returns boolean

    true if command was applied.

Protected tryBuildRangeWithPreviousItemWhenLastItemWasDeselected

  • tryBuildRangeWithPreviousItemWhenLastItemWasDeselected(ctrlKeyPressed: boolean, shiftKeyPressed: boolean): boolean
  • Tries to select element that is previous to the last processed element and last processed element was deselected.

    Parameters

    • ctrlKeyPressed: boolean

      true if Ctrl key was pressed.

    • shiftKeyPressed: boolean

      true if Shift key was pressed.

    Returns boolean

    true if command was applied.

Protected tryDeselectLastItemInRange

  • tryDeselectLastItemInRange(shiftKeyPressed: boolean): boolean
  • Tries to deselect last selected element when Shift+Arrow Up combination pressed (Shift+Arrow Left if {@link SelectionAreaConfig.horizontal} is true).

    Parameters

    • shiftKeyPressed: boolean

      true if Shift key was pressed.

    Returns boolean

    true if command was applied.

Protected tryDeselectLastItemInReversedRange

  • tryDeselectLastItemInReversedRange(shiftKeyPressed: boolean): boolean
  • Tries to deselect last selected element when Shift+Arrow Down combination pressed (Shift+Arrow Right if {@link SelectionAreaConfig.horizontal} is true).

    Parameters

    • shiftKeyPressed: boolean

      true if Shift key was pressed.

    Returns boolean

    true if command was applied.

Protected tryInitialSelectionOfFirstItem

  • tryInitialSelectionOfFirstItem(): boolean

Protected trySelectAll

  • trySelectAll(ctrlPressed: boolean, shiftPressed: boolean): boolean
  • Tries to select all items if Ctrl+A combination was pressed.

    Parameters

    • ctrlPressed: boolean
    • shiftPressed: boolean

    Returns boolean

    true if command was applied.

Protected trySelectAllItemsUpToFirst

  • trySelectAllItemsUpToFirst(ctrlKeyPressed: boolean, shiftKeyPressed: boolean): boolean
  • Tries to select all elements starting from last selected element up to first element in SelectionService.items when Ctrl+Shift+Arrow Up combination was pressed (Ctrl+Shift+Arrow Left if {@link SelectionAreaConfig.horizontal} is true).

    Parameters

    • ctrlKeyPressed: boolean

      true if Ctrl key was pressed.

    • shiftKeyPressed: boolean

      true if Shift key was pressed.

    Returns boolean

    true if command was applied.

Protected trySelectAllItemsUpToLast

  • trySelectAllItemsUpToLast(ctrlKeyPressed: boolean, shiftKeyPressed: boolean): boolean
  • Tries to select all elements starting from last selected element up to last element in SelectionService.items when Ctrl+Shift+Arrow Down combination was pressed (Ctrl+Shift+Arrow Right if {@link SelectionAreaConfig.horizontal} is true).

    Parameters

    • ctrlKeyPressed: boolean

      true if Ctrl key was pressed.

    • shiftKeyPressed: boolean

      true if Shift key was pressed.

    Returns boolean

    true if command was applied.

Protected trySelectFirstItem

  • trySelectFirstItem(ctrlKeyPressed: boolean, shiftKeyPressed: boolean): boolean
  • Tries to select first element in SelectionService.items when Ctrl+Arrow Up combination was pressed (Ctrl+Arrow Left if {@link SelectionAreaConfig.horizontal} is true).

    Parameters

    • ctrlKeyPressed: boolean

      true if Ctrl key was pressed.

    • shiftKeyPressed: boolean

      true if Shift key was pressed (with pressed Shift this command would not be applied).

    Returns boolean

    true if command was applied.

Protected trySelectLastItem

  • trySelectLastItem(ctrlKeyPressed: boolean, shiftKeyPressed: boolean): boolean
  • Tries to select last element in SelectionService.items when Ctrl+Arrow Down combination was pressed (Ctrl+Arrow Right if {@link SelectionAreaConfig.horizontal} is true).

    Parameters

    • ctrlKeyPressed: boolean

      true if Ctrl key was pressed.

    • shiftKeyPressed: boolean

      true if Shift key was pressed (with pressed Shift this command would not be applied).

    Returns boolean

    true if command was applied.

Protected trySelectNextItem

  • trySelectNextItem(shiftKeyPressed: boolean): boolean
  • Tries to select next item when Arrow Down was pressed (Right Arrow if {@link SelectionAreaConfig.horizontal} is true).

    If Shift was pressed and {@link SelectionAreaConfig.multiple} is 'true' then elements selected before stays selected.

    Parameters

    • shiftKeyPressed: boolean

      true if Shift key was pressed.

    Returns boolean

    true if command was applied.

Protected trySelectPreviousItem

  • trySelectPreviousItem(shiftKeyPressed: boolean): boolean
  • Tries to select previous item when Arrow Up was pressed (Arrow Left if {@link SelectionAreaConfig.horizontal} is true).

    If Shift was pressed and {@link SelectionAreaConfig.multiple} is 'true' then elements selected before stays selected.

    Parameters

    • shiftKeyPressed: boolean

      true if Shift key was pressed.

    Returns boolean

    true if command was applied.

Generated using TypeDoc