1 | /**
|
---|
2 | * @license
|
---|
3 | * Copyright Google LLC All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
6 | * found in the LICENSE file at https://angular.io/license
|
---|
7 | */
|
---|
8 | import { QueryList } from '@angular/core';
|
---|
9 | import { Subject } from 'rxjs';
|
---|
10 | /** This interface is for items that can be passed to a ListKeyManager. */
|
---|
11 | export interface ListKeyManagerOption {
|
---|
12 | /** Whether the option is disabled. */
|
---|
13 | disabled?: boolean;
|
---|
14 | /** Gets the label for this option. */
|
---|
15 | getLabel?(): string;
|
---|
16 | }
|
---|
17 | /** Modifier keys handled by the ListKeyManager. */
|
---|
18 | export declare type ListKeyManagerModifierKey = 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey';
|
---|
19 | /**
|
---|
20 | * This class manages keyboard events for selectable lists. If you pass it a query list
|
---|
21 | * of items, it will set the active item correctly when arrow events occur.
|
---|
22 | */
|
---|
23 | export declare class ListKeyManager<T extends ListKeyManagerOption> {
|
---|
24 | private _items;
|
---|
25 | private _activeItemIndex;
|
---|
26 | private _activeItem;
|
---|
27 | private _wrap;
|
---|
28 | private readonly _letterKeyStream;
|
---|
29 | private _typeaheadSubscription;
|
---|
30 | private _vertical;
|
---|
31 | private _horizontal;
|
---|
32 | private _allowedModifierKeys;
|
---|
33 | private _homeAndEnd;
|
---|
34 | /**
|
---|
35 | * Predicate function that can be used to check whether an item should be skipped
|
---|
36 | * by the key manager. By default, disabled items are skipped.
|
---|
37 | */
|
---|
38 | private _skipPredicateFn;
|
---|
39 | private _pressedLetters;
|
---|
40 | constructor(_items: QueryList<T> | T[]);
|
---|
41 | /**
|
---|
42 | * Stream that emits any time the TAB key is pressed, so components can react
|
---|
43 | * when focus is shifted off of the list.
|
---|
44 | */
|
---|
45 | readonly tabOut: Subject<void>;
|
---|
46 | /** Stream that emits whenever the active item of the list manager changes. */
|
---|
47 | readonly change: Subject<number>;
|
---|
48 | /**
|
---|
49 | * Sets the predicate function that determines which items should be skipped by the
|
---|
50 | * list key manager.
|
---|
51 | * @param predicate Function that determines whether the given item should be skipped.
|
---|
52 | */
|
---|
53 | skipPredicate(predicate: (item: T) => boolean): this;
|
---|
54 | /**
|
---|
55 | * Configures wrapping mode, which determines whether the active item will wrap to
|
---|
56 | * the other end of list when there are no more items in the given direction.
|
---|
57 | * @param shouldWrap Whether the list should wrap when reaching the end.
|
---|
58 | */
|
---|
59 | withWrap(shouldWrap?: boolean): this;
|
---|
60 | /**
|
---|
61 | * Configures whether the key manager should be able to move the selection vertically.
|
---|
62 | * @param enabled Whether vertical selection should be enabled.
|
---|
63 | */
|
---|
64 | withVerticalOrientation(enabled?: boolean): this;
|
---|
65 | /**
|
---|
66 | * Configures the key manager to move the selection horizontally.
|
---|
67 | * Passing in `null` will disable horizontal movement.
|
---|
68 | * @param direction Direction in which the selection can be moved.
|
---|
69 | */
|
---|
70 | withHorizontalOrientation(direction: 'ltr' | 'rtl' | null): this;
|
---|
71 | /**
|
---|
72 | * Modifier keys which are allowed to be held down and whose default actions will be prevented
|
---|
73 | * as the user is pressing the arrow keys. Defaults to not allowing any modifier keys.
|
---|
74 | */
|
---|
75 | withAllowedModifierKeys(keys: ListKeyManagerModifierKey[]): this;
|
---|
76 | /**
|
---|
77 | * Turns on typeahead mode which allows users to set the active item by typing.
|
---|
78 | * @param debounceInterval Time to wait after the last keystroke before setting the active item.
|
---|
79 | */
|
---|
80 | withTypeAhead(debounceInterval?: number): this;
|
---|
81 | /**
|
---|
82 | * Configures the key manager to activate the first and last items
|
---|
83 | * respectively when the Home or End key is pressed.
|
---|
84 | * @param enabled Whether pressing the Home or End key activates the first/last item.
|
---|
85 | */
|
---|
86 | withHomeAndEnd(enabled?: boolean): this;
|
---|
87 | /**
|
---|
88 | * Sets the active item to the item at the index specified.
|
---|
89 | * @param index The index of the item to be set as active.
|
---|
90 | */
|
---|
91 | setActiveItem(index: number): void;
|
---|
92 | /**
|
---|
93 | * Sets the active item to the specified item.
|
---|
94 | * @param item The item to be set as active.
|
---|
95 | */
|
---|
96 | setActiveItem(item: T): void;
|
---|
97 | /**
|
---|
98 | * Sets the active item depending on the key event passed in.
|
---|
99 | * @param event Keyboard event to be used for determining which element should be active.
|
---|
100 | */
|
---|
101 | onKeydown(event: KeyboardEvent): void;
|
---|
102 | /** Index of the currently active item. */
|
---|
103 | get activeItemIndex(): number | null;
|
---|
104 | /** The active item. */
|
---|
105 | get activeItem(): T | null;
|
---|
106 | /** Gets whether the user is currently typing into the manager using the typeahead feature. */
|
---|
107 | isTyping(): boolean;
|
---|
108 | /** Sets the active item to the first enabled item in the list. */
|
---|
109 | setFirstItemActive(): void;
|
---|
110 | /** Sets the active item to the last enabled item in the list. */
|
---|
111 | setLastItemActive(): void;
|
---|
112 | /** Sets the active item to the next enabled item in the list. */
|
---|
113 | setNextItemActive(): void;
|
---|
114 | /** Sets the active item to a previous enabled item in the list. */
|
---|
115 | setPreviousItemActive(): void;
|
---|
116 | /**
|
---|
117 | * Allows setting the active without any other effects.
|
---|
118 | * @param index Index of the item to be set as active.
|
---|
119 | */
|
---|
120 | updateActiveItem(index: number): void;
|
---|
121 | /**
|
---|
122 | * Allows setting the active item without any other effects.
|
---|
123 | * @param item Item to be set as active.
|
---|
124 | */
|
---|
125 | updateActiveItem(item: T): void;
|
---|
126 | /**
|
---|
127 | * This method sets the active item, given a list of items and the delta between the
|
---|
128 | * currently active item and the new active item. It will calculate differently
|
---|
129 | * depending on whether wrap mode is turned on.
|
---|
130 | */
|
---|
131 | private _setActiveItemByDelta;
|
---|
132 | /**
|
---|
133 | * Sets the active item properly given "wrap" mode. In other words, it will continue to move
|
---|
134 | * down the list until it finds an item that is not disabled, and it will wrap if it
|
---|
135 | * encounters either end of the list.
|
---|
136 | */
|
---|
137 | private _setActiveInWrapMode;
|
---|
138 | /**
|
---|
139 | * Sets the active item properly given the default mode. In other words, it will
|
---|
140 | * continue to move down the list until it finds an item that is not disabled. If
|
---|
141 | * it encounters either end of the list, it will stop and not wrap.
|
---|
142 | */
|
---|
143 | private _setActiveInDefaultMode;
|
---|
144 | /**
|
---|
145 | * Sets the active item to the first enabled item starting at the index specified. If the
|
---|
146 | * item is disabled, it will move in the fallbackDelta direction until it either
|
---|
147 | * finds an enabled item or encounters the end of the list.
|
---|
148 | */
|
---|
149 | private _setActiveItemByIndex;
|
---|
150 | /** Returns the items as an array. */
|
---|
151 | private _getItemsArray;
|
---|
152 | }
|
---|