From 110c0c0aa913fdc8cad273f2a36b2e25fd65c396 Mon Sep 17 00:00:00 2001 From: Kevin Buhmann Date: Tue, 28 Jun 2022 10:12:30 -0500 Subject: [PATCH] feat(datagrid): change focused action on arrow key press fixes VPAT-600 --- projects/angular/clarity.api.md | 14 ++++----- .../data/datagrid/datagrid-action-overflow.ts | 30 +++++++++++++++---- .../src/data/datagrid/datagrid.module.ts | 2 ++ 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/projects/angular/clarity.api.md b/projects/angular/clarity.api.md index acf500c036..7269d1cb41 100644 --- a/projects/angular/clarity.api.md +++ b/projects/angular/clarity.api.md @@ -86,7 +86,7 @@ export class ClarityModule { // Warning: (ae-forgotten-export) The symbol "i20" needs to be exported by the entry point index.d.ts // // (undocumented) - static ɵmod: i0.ɵɵNgModuleDeclaration; + static ɵmod: i0.ɵɵNgModuleDeclaration; } // @public (undocumented) @@ -860,10 +860,10 @@ export class ClrComboboxModule { // Warning: (ae-forgotten-export) The symbol "i4" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "i5" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "i6" needs to be exported by the entry point index.d.ts - // Warning: (ae-forgotten-export) The symbol "i10" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "i48" needs to be exported by the entry point index.d.ts // // (undocumented) - static ɵmod: i0.ɵɵNgModuleDeclaration; + static ɵmod: i0.ɵɵNgModuleDeclaration; } // @public (undocumented) @@ -1628,7 +1628,7 @@ export class ClrDatagridModule { // Warning: (ae-forgotten-export) The symbol "i44" needs to be exported by the entry point index.d.ts // // (undocumented) - static ɵmod: i0.ɵɵNgModuleDeclaration; + static ɵmod: i0.ɵɵNgModuleDeclaration; } // @public (undocumented) @@ -2467,7 +2467,7 @@ export class ClrFormsModule { // Warning: (ae-forgotten-export) The symbol "i12" needs to be exported by the entry point index.d.ts // // (undocumented) - static ɵmod: i0.ɵɵNgModuleDeclaration; + static ɵmod: i0.ɵɵNgModuleDeclaration; } // @public (undocumented) @@ -4210,7 +4210,7 @@ export class ClrTabsModule { // Warning: (ae-forgotten-export) The symbol "i11" needs to be exported by the entry point index.d.ts // // (undocumented) - static ɵmod: i0.ɵɵNgModuleDeclaration; + static ɵmod: i0.ɵɵNgModuleDeclaration; } // @public (undocumented) @@ -4820,7 +4820,7 @@ export class ClrWizardModule { // Warning: (ae-forgotten-export) The symbol "i11" needs to be exported by the entry point index.d.ts // // (undocumented) - static ɵmod: i0.ɵɵNgModuleDeclaration; + static ɵmod: i0.ɵɵNgModuleDeclaration; } // @public diff --git a/projects/angular/src/data/datagrid/datagrid-action-overflow.ts b/projects/angular/src/data/datagrid/datagrid-action-overflow.ts index 36e4f547bd..4c83978b0f 100644 --- a/projects/angular/src/data/datagrid/datagrid-action-overflow.ts +++ b/projects/angular/src/data/datagrid/datagrid-action-overflow.ts @@ -5,9 +5,20 @@ */ import { isPlatformBrowser } from '@angular/common'; -import { Component, EventEmitter, Inject, Input, NgZone, OnDestroy, Output, PLATFORM_ID } from '@angular/core'; +import { + Component, + EventEmitter, + Inject, + Input, + NgZone, + OnDestroy, + Output, + PLATFORM_ID, + ViewChild, +} from '@angular/core'; import { Subscription } from 'rxjs'; +import { ClrKeyFocus } from '../../utils/focus/key-focus'; import { ClrCommonStringsService } from '../../utils/i18n/common-strings.service'; import { UNIQUE_ID, UNIQUE_ID_PROVIDER } from '../../utils/id-generator/id-generator.service'; import { ClrAlignment } from '../../utils/popover/enums/alignment.enum'; @@ -45,6 +56,7 @@ let clrDgActionId = 0; [id]="popoverId" [attr.aria-hidden]="!open" [attr.id]="popoverId" + clrKeyFocus clrFocusTrap (click)="closeOverflowContent($event)" *clrPopoverContent="open; at: smartPosition; outsideClickToClose: true; scrollToClose: true" @@ -62,6 +74,8 @@ export class ClrDatagridActionOverflow implements OnDestroy { content: ClrAlignment.CENTER, }; + @ViewChild(ClrKeyFocus) private readonly keyFocus: ClrKeyFocus; + constructor( private rowActionService: RowActionService, public commonStrings: ClrCommonStringsService, @@ -75,7 +89,7 @@ export class ClrDatagridActionOverflow implements OnDestroy { this.smartToggleService.openChange.subscribe(openState => { this.open = openState; if (openState) { - this.focusFirstButton(); + this.initializeFocus(); } }) ); @@ -91,13 +105,17 @@ export class ClrDatagridActionOverflow implements OnDestroy { this.smartToggleService.toggleWithEvent(event); } - private focusFirstButton(): void { + private initializeFocus(): void { if (isPlatformBrowser(this.platformId)) { this.zone.runOutsideAngular(() => { setTimeout(() => { - const firstButton: HTMLButtonElement | null = document.querySelector('button.action-item'); - if (firstButton) { - firstButton.focus(); + const buttons = Array.from(document.querySelectorAll('button.action-item')); + + if (buttons.length) { + this.keyFocus.current = 0; + this.keyFocus.focusableItems = buttons; + + this.keyFocus.focusCurrent(); } }); }); diff --git a/projects/angular/src/data/datagrid/datagrid.module.ts b/projects/angular/src/data/datagrid/datagrid.module.ts index b65f726878..a39b81914f 100644 --- a/projects/angular/src/data/datagrid/datagrid.module.ts +++ b/projects/angular/src/data/datagrid/datagrid.module.ts @@ -28,6 +28,7 @@ import { ClrConditionalModule } from '../../utils/conditional/conditional.module import { ClrDragAndDropModule } from '../../utils/drag-and-drop/drag-and-drop.module'; import { ClrFocusTrapModule } from '../../utils/focus-trap/focus-trap.module'; import { ClrFocusOnViewInitModule } from '../../utils/focus/focus-on-view-init/focus-on-view-init.module'; +import { ClrKeyFocusModule } from '../../utils/focus/key-focus/key-focus.module'; import { ClrLoadingModule } from '../../utils/loading/loading.module'; import { ClrOutsideClickModule } from '../../utils/outside-click/outside-click.module'; import { ClrPopoverModuleNext } from '../../utils/popover/popover.module'; @@ -127,6 +128,7 @@ export const CLR_DATAGRID_DIRECTIVES: Type[] = [ ClrDragAndDropModule, ClrSpinnerModule, ClrPopoverModuleNext, + ClrKeyFocusModule, ClrFocusTrapModule, ClrFocusOnViewInitModule, ],