MCPcopy Index your code
hub / github.com/UI5/webcomponents / _onKeyDown

Method _onKeyDown

packages/main/src/TableVirtualizer.ts:236–283  ·  view source on GitHub ↗
(e: KeyboardEvent)

Source from the content-addressed store, hash-verified

234 }
235
236 _onKeyDown(e: KeyboardEvent) {
237 if (!this._table) {
238 return;
239 }
240
241 let scrollTopChange = 0;
242 const rows = this._table.rows;
243 const firstRow = rows[0];
244 const lastRow = rows[rows.length - 1];
245 const hasDataBeforeFirstRow = firstRow.position !== 0;
246 const hasDataAfterLastRow = lastRow.position !== this.rowCount - 1;
247 const tableNavigation = this._table._tableNavigation!;
248 const activeElement = getActiveElement() as HTMLElement;
249
250 if (isTabNext(e) && hasDataAfterLastRow && getTabbableElements(this._rowsContainer).pop() === activeElement) {
251 this._tabBlockingState = TabBlocking.Next;
252 lastRow.attachInvalidate(this._onRowInvalidateBound);
253 scrollTopChange = this.rowHeight;
254 } else if (isTabPrevious(e) && hasDataBeforeFirstRow && getTabbableElements(this._rowsContainer).shift() === activeElement) {
255 this._tabBlockingState = TabBlocking.Previous;
256 firstRow.attachInvalidate(this._onRowInvalidateBound);
257 scrollTopChange = this.rowHeight * -1;
258 } else if (hasDataAfterLastRow && tableNavigation._getNavigationItemsOfRow(lastRow).includes(activeElement)) {
259 if (isDown(e) || isDownShift(e)) {
260 scrollTopChange = this.rowHeight;
261 } else if (isPageDown(e)) {
262 scrollTopChange = this._visibleRowCount * this.rowHeight;
263 } else if (isEnd(e) && activeElement === lastRow) {
264 scrollTopChange = this.rowCount * this.rowHeight;
265 }
266 } else if (hasDataBeforeFirstRow && tableNavigation._getNavigationItemsOfRow(firstRow).includes(activeElement)) {
267 if (isUp(e) || isUpShift(e)) {
268 scrollTopChange = this.rowHeight * -1;
269 } else if (isPageUp(e)) {
270 scrollTopChange = this._visibleRowCount * this.rowHeight * -1;
271 } else if (isHome(e) && activeElement === firstRow) {
272 scrollTopChange = this.rowCount * this.rowHeight * -1;
273 }
274 }
275
276 if (scrollTopChange) {
277 const scrollTop = this._table.scrollTop;
278 this._scrollContainer.scrollTop += scrollTopChange;
279 if (this._scrollContainer.scrollTop !== scrollTop) {
280 e.preventDefault();
281 }
282 }
283 }
284}
285
286TableVirtualizer.define();

Callers

nothing calls this directly

Calls 14

getActiveElementFunction · 0.85
isTabNextFunction · 0.85
getTabbableElementsFunction · 0.85
isTabPreviousFunction · 0.85
isDownFunction · 0.85
isDownShiftFunction · 0.85
isPageDownFunction · 0.85
isEndFunction · 0.85
isUpFunction · 0.85
isUpShiftFunction · 0.85
isPageUpFunction · 0.85
isHomeFunction · 0.85

Tested by

no test coverage detected