From 11f1f6349a4e7672dd3c7eb9ccc05fee1ae16290 Mon Sep 17 00:00:00 2001 From: William Martin Date: Mon, 19 May 2025 11:29:26 -0400 Subject: [PATCH] update jsdoc --- .../src/a11y/a11y-grid.directive.ts | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/libs/components/src/a11y/a11y-grid.directive.ts b/libs/components/src/a11y/a11y-grid.directive.ts index b91cbe0b191..65941c9ae2c 100644 --- a/libs/components/src/a11y/a11y-grid.directive.ts +++ b/libs/components/src/a11y/a11y-grid.directive.ts @@ -40,7 +40,7 @@ export class A11yGridDirective { /** The row that currently has focus */ private activeRow = signal(0); - private renderedRow = computed(() => this.convertRealRowToRenderedRow(this.activeRow())); + private renderedRow = computed(() => this.convertRealRowToViewportRow(this.activeRow())); /** The cell that currently has focus */ private activeCol = signal(0); @@ -98,14 +98,21 @@ export class A11yGridDirective { event.preventDefault(); } - private convertRealRowToRenderedRow(row: number) { - const range = this.viewPort - ? this.viewPort.getRenderedRange() - : { start: 0, end: this.numRows }; - if (row >= range.start && row < range.end) { - return row - range.start; // Convert real row index to rendered row index + /** + * Converts real row index to viewport row index. The two will differ when list virtualization is used. + * @param realRow A row index based on the total number of rows in the grid + * @returns A row index based on the total number rows being rendered in the viewport. + */ + private convertRealRowToViewportRow(realRow: number): number { + if (!this.viewPort) { + return realRow; } - return row; + + const { start, end } = this.viewPort.getRenderedRange(); + if (realRow >= start && realRow < end) { + return realRow - start; + } + return realRow; } /** Move focus via a delta against the currently active gridcell */ @@ -113,7 +120,7 @@ export class A11yGridDirective { let nextCol = this.activeCol() + colDelta; let nextRow = this.activeRow() + rowDelta; - const getNumColumns = (r: number) => this.grid()[this.convertRealRowToRenderedRow(r)].length; + const getNumColumns = (r: number) => this.grid()[this.convertRealRowToViewportRow(r)].length; // Row upper bound if (nextRow >= this.numRows) {