From e1f6828282fd470b210f3b49ef14485e8ad0bca9 Mon Sep 17 00:00:00 2001 From: William Martin Date: Thu, 29 May 2025 00:27:36 -0400 Subject: [PATCH] skip over disabled entries --- .../src/a11y/a11y-grid.directive.ts | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/libs/components/src/a11y/a11y-grid.directive.ts b/libs/components/src/a11y/a11y-grid.directive.ts index f3db9ca4ee2..8a079577c1d 100644 --- a/libs/components/src/a11y/a11y-grid.directive.ts +++ b/libs/components/src/a11y/a11y-grid.directive.ts @@ -105,21 +105,37 @@ export class A11yGridDirective { // Only set activeRow after ensuring the row is rendered this.activeRow.set(nextRow); - this.focusIfPossible(); + const didFocus = this.focusIfPossible(); + if (didFocus) { + return; + } + + this.updateCol(-1); } private updateCol(delta: number) { this.activeCol.update((prev) => this.clamp(0, prev + delta, this.numColumns() - 1)); - this.focusIfPossible(); + const didFocus = this.focusIfPossible(); + if (didFocus) { + return; + } + + this.updateCol(Math.sign(delta)); } - private focusIfPossible() { + private focusIfPossible(): boolean { const focusTarget = this.focusTarget(); - if (focusTarget && document.body.contains(focusTarget)) { + if ( + focusTarget && + document.body.contains(focusTarget) && + !(focusTarget as HTMLButtonElement).disabled + ) { focusTarget.tabIndex = 0; focusTarget.focus(); + return true; } + return false; } private clamp(min: number, n: number, max: number) {