Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2273x 2273x 1x 1x 136x 136x 1x 1x 55905x 55905x 1x 1x 146x 146x 146x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 98x 98x 1x 1x 126x 126x 126x 126x 126x 1x 1x 252x 252x 1x 1x 45x 45x 1x 1x 136x 101x 101x 100x 101x 101x 136x 136x 136x 136x 136x 133x 133x 3x 3x 136x 136x 1x 1x 1x 42x 42x 17x 42x 42x 42x 42x 42x 42x 42x 1x 1x 1x 18x 18x 1x 1x 1x 56x 56x 56x 17x 17x 17x 43x 7x 7x 7x 45x 14x 14x 14x 50x 2x 2x 2x 2x 2x 2x 2x 56x 14x 2x 2x 12x 10x 10x 56x 56x 56x 56x 1x 1x 1x 2x 2x 2x 2x 2x 1x 1x 1x 17x 17x 17x 17x 17x 1x 1x 1x 14x 14x 14x 14x 14x 1x 1x 1x 7x 7x 7x 7x 7x 1x 1x 2x 2x 1x 1x 126x 126x 954x 954x 126x 126x 126x 1x 1x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 44x 18x 18x 18x 18x 18x 10x 10x 10x 10x 1x 2x 2x 2x 2x 2x 1x 1x 10x 10x 10x 4x 10x 10x 1x 1x 10x 7x 7x 10x 10x 1x | import { ChangeDetectorRef, EventEmitter, Injectable } from '@angular/core'; import { isPrintableCharacter } from '../utils/internal-utils'; import { Converter, Item, Key } from '../utils/util.types'; import { VirtualListBoxItemDirective } from './virtual-listbox-item.directive'; import { ListboxSelectEvent } from './virtual-listbox.directive'; @Injectable() export class VirtualListboxService { public get activeDescendant(): string | null { return this.hasFocus ? this._activeDescendant : null; // Only render active descendant if it has focus otherwise FF & NVDA thinks the list has the focus } public set activeDescendant(value: string | null) { this._activeDescendant = value; } public get value(): Key | undefined { return this._value; } public set value(value: Key | undefined) { this._value = value; this.children.find(c => c.item.key === value)?.scrollIntoView(); } public readonly onSelect: EventEmitter<ListboxSelectEvent> = new EventEmitter<ListboxSelectEvent>(); public readonly onKeypress: EventEmitter<KeyboardEvent> = new EventEmitter<KeyboardEvent>(); private _value?: Key; private hasFocus = false; private focusedListIndex = -1; private _activeDescendant: string | null = null; private itemSearchText = ''; private clearTimer?: ReturnType<typeof setTimeout>; private children: readonly VirtualListBoxItemDirective[] = []; constructor(private change: ChangeDetectorRef) {} public itemIdComputer: Converter<Item, string> = i => 'item-' + i.key; public setItems(viewChildren: readonly VirtualListBoxItemDirective[]): void { this.children = viewChildren; this.focusedListIndex = -1; this._activeDescendant = null; this.connectMenuItems(); } public getItems(): readonly VirtualListBoxItemDirective[] { return this.children; } public selectItem(item: Item, open: boolean): void { this.onSelect.emit({ key: item.key, open }); } public updateFocusedIndex(idx: number) { if (this.focusedListIndex != -1) { const prevItem = this.children.at(this.focusedListIndex); if (prevItem) { prevItem.focused = false; } } this.focusedListIndex = idx; const item = this.children.at(idx); if (item) { item.focused = true; this.activeDescendant = this.itemIdComputer(item.item); } else { this.activeDescendant = null; } } /** @ignore */ public onFocus(): void { this.hasFocus = true; if (this.focusedListIndex === -1 && this.children.length > 0) { this.updateFocusedIndex(0); } // Do not sync with selection - eg windows explorer does not do it either if (this.focusedListIndex !== -1) { this.children.at(this.focusedListIndex)?.scrollIntoView(); } } /** @ignore */ public onBlur(): void { this.hasFocus = false; } /** @ignore */ public onKeyDown(event: KeyboardEvent): void { const key = event.key; switch (key) { case 'Enter': this._impl_onEnter(); event.preventDefault(); break; case 'ArrowUp': this._impl_onUp(); event.preventDefault(); break; case 'ArrowDown': this._impl_onDown(); event.preventDefault(); break; case 'End': this._impl_onEnd(); event.preventDefault(); break; case 'Home': this.updateFocusedIndex(0); event.preventDefault(); break; default: if (key === ' ' && this.itemSearchText === '') { this._impl_onSpace(); event.preventDefault(); } else if (key === ' ' || isPrintableCharacter(key)) { this.moveByKey(key); event.preventDefault(); } } this.onKeypress.emit(event); } /** @ignore */ protected _impl_onSpace(): void { const el = this.children.at(this.focusedListIndex); if (el && !el.ignoreSelection) { this.selectItem(el.item.item, false); } } /** @ignore */ protected _impl_onEnter(): void { const el = this.children.at(this.focusedListIndex); if (el && !el.ignoreSelection) { this.selectItem(el.item.item, true); } } /** @ignore */ protected _impl_onDown(): void { if (this.focusedListIndex == -1) { this.updateFocusedIndex(0); } else if (this.focusedListIndex + 1 < this.children.length) { this.updateFocusedIndex(this.focusedListIndex + 1); } } /** @ignore */ protected _impl_onUp(): void { if (this.focusedListIndex == -1) { this.updateFocusedIndex(this.children.length - 1); } else if (this.focusedListIndex - 1 >= 0) { this.updateFocusedIndex(this.focusedListIndex - 1); } } protected _impl_onEnd(): void { this.updateFocusedIndex(this.children.length - 1); } private connectMenuItems(): void { const size = this.getItems().length; this.getItems().forEach((e, index) => { e.updateItem(index, size); e.focused = false; }); this.change.detectChanges(); } private moveByKey(char: string): void { const curIdx = this.focusedListIndex === -1 ? 0 : this.focusedListIndex; const firstSearch = this.itemSearchText === ''; this.itemSearchText += char; this.clearSearchTimer(); this.clearTimer = setTimeout(() => { this.itemSearchText = ''; }, 1000); let indx = this.children.findIndex((itemDirective, idx) => { const indexCheck = firstSearch ? idx > curIdx : idx >= curIdx; return ( indexCheck && itemDirective.item.label .toLocaleLowerCase() .includes(this.itemSearchText.toLocaleLowerCase()) ); }); if (indx === -1) { indx = this.children.findIndex((itemDirective, idx) => { return ( idx <= curIdx && itemDirective.item.label .toLocaleLowerCase() .includes(this.itemSearchText.toLocaleLowerCase()) ); }); } if (indx !== -1 && indx !== curIdx) { this.updateFocusedIndex(indx); } } private clearSearchTimer() { if (this.clearTimer !== undefined) { clearTimeout(this.clearTimer); this.clearTimer = undefined; } } } |