From 66bb385a39478fefc7a137b247997800cd44274a Mon Sep 17 00:00:00 2001 From: Aayush Rohila <112551534+arohilaGL@users.noreply.github.com> Date: Wed, 22 Mar 2023 14:38:27 +0530 Subject: [PATCH] =?UTF-8?q?[ACS-4746]=20Returning=20focus=20to=20trigger?= =?UTF-8?q?=20element=20after=20restore=20option=20is=E2=80=A6=20(#8359)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [ACS-4746] Returning focus to trigger element after restore option is selected and manage version modal is closed * [ACS-4746] Returning focus to trigger element after restore in manage versions PR * [ACS-4746] Returning focus to trigger element after restore option is selected in manage version and test cases for the change. --- .../datatable/datatable.component.spec.ts | 28 +++++++++++++++++++ .../datatable/datatable.component.ts | 12 ++++++++ 2 files changed, 40 insertions(+) diff --git a/lib/core/src/lib/datatable/components/datatable/datatable.component.spec.ts b/lib/core/src/lib/datatable/components/datatable/datatable.component.spec.ts index 195ad20b69..128f8a9ecf 100644 --- a/lib/core/src/lib/datatable/components/datatable/datatable.component.spec.ts +++ b/lib/core/src/lib/datatable/components/datatable/datatable.component.spec.ts @@ -1345,6 +1345,34 @@ describe('DataTable', () => { expect(idColumn.innerText).toContain('ID'); expect(nameColumn.innerText).toContain('CUSTOM HEADER'); }); + + it('should set isContextMenuSource to true for row whose id matches selectedRowId', () => { + const rows = [{ + id: '1234', + isContextMenuSource: false + }, { + id: '2345', + isContextMenuSource: false + }, { + id: '3456', + isContextMenuSource: false + }] as DataRow[]; + const row = { + id: '2345', + isContextMenuSource: false + } as DataRow; + dataTable.data = new ObjectDataTableAdapter( + rows, + [new ObjectDataColumn({ key: 'id' }), + new ObjectDataColumn({ key: 'isContextMenuSource' })] + ); + + dataTable.markRowAsContextMenuSource(row); + fixture.detectChanges(); + + expect(dataTable.selectedRowId).toEqual('2345'); + expect(row.isContextMenuSource).toBeTrue(); + }); }); describe('Accesibility', () => { diff --git a/lib/core/src/lib/datatable/components/datatable/datatable.component.ts b/lib/core/src/lib/datatable/components/datatable/datatable.component.ts index 7d553d74b9..737c3d9620 100644 --- a/lib/core/src/lib/datatable/components/datatable/datatable.component.ts +++ b/lib/core/src/lib/datatable/components/datatable/datatable.component.ts @@ -226,6 +226,7 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges, isSelectAllIndeterminate: boolean = false; isSelectAllChecked: boolean = false; selection = new Array(); + selectedRowId: string = ''; isDraggingHeaderColumn = false; hoveredHeaderColumnIndex = -1; @@ -287,6 +288,9 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges, ngOnChanges(changes: SimpleChanges) { this.initAndSubscribeClickStream(); + if(this.selectedRowId) { + this.setRowAsContextSource(); + } const dataChanges = changes['data']; const rowChanges = changes['rows']; @@ -782,10 +786,18 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges, } markRowAsContextMenuSource(selectedRow: DataRow): void { + this.selectedRowId = selectedRow.id ? selectedRow.id : ''; this.data.getRows().forEach((row) => row.isContextMenuSource = false); selectedRow.isContextMenuSource = true; } + private setRowAsContextSource(): void { + const selectedRow = this.data.getRows().find((row) => this.selectedRowId === row.id); + if(selectedRow) { + selectedRow.isContextMenuSource = true; + } + } + getSortingKey(): string | null { if (this.data.getSorting()) { return this.data.getSorting().key;