Skip to content

Commit 00f70ed

Browse files
authored
fix(igxGrid): Add handling for outlet in case actionstrip is added post init (#17162)
1 parent 2b99198 commit 00f70ed

File tree

3 files changed

+87
-2
lines changed

3 files changed

+87
-2
lines changed

projects/igniteui-angular/grids/grid/src/grid-add-row.spec.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { TestBed, fakeAsync, tick, waitForAsync } from '@angular/core/testing';
44
import { DebugElement } from '@angular/core';
55
import { GridFunctions, GridSummaryFunctions } from '../../../test-utils/grid-functions.spec';
66
import {
7-
IgxAddRowComponent, IgxGridRowEditingDefinedColumnsComponent, IgxGridRowEditingTransactionComponent
7+
IgxAddRowComponent, IgxGridRowEditingDefinedColumnsComponent, IgxGridRowEditingTransactionComponent,
8+
GridDynamicActionStripComponent
89
} from '../../../test-utils/grid-samples.spec';
910

1011
import { By } from '@angular/platform-browser';
@@ -45,7 +46,8 @@ describe('IgxGrid - Row Adding #grid', () => {
4546
IgxGridRowEditingTransactionComponent,
4647
IgxGridRowEditingDefinedColumnsComponent,
4748
ColumnLayoutTestComponent,
48-
DefaultGridMasterDetailComponent
49+
DefaultGridMasterDetailComponent,
50+
GridDynamicActionStripComponent
4951
],
5052
providers: [
5153
IgxGridMRLNavigationService
@@ -1121,4 +1123,32 @@ describe('IgxGrid - Row Adding #grid', () => {
11211123
expect(grid.rowChangesCount).toEqual(3);
11221124
});
11231125
});
1126+
1127+
describe('ActionStrip - Dynamic Addition', () => {
1128+
beforeEach(() => {
1129+
fixture = TestBed.createComponent(GridDynamicActionStripComponent);
1130+
fixture.detectChanges();
1131+
grid = fixture.componentInstance.grid;
1132+
});
1133+
1134+
it('Should set outlet for actionstrip menu when added post-init', async () => {
1135+
// Verify no actionstrip initially
1136+
expect(fixture.componentInstance.actionStrip).toBeUndefined();
1137+
expect(grid.actionStrip).toBeUndefined();
1138+
1139+
// Add the actionstrip dynamically
1140+
fixture.componentInstance.showActionStrip = true;
1141+
fixture.detectChanges();
1142+
await wait(16);
1143+
1144+
// Get reference to the actionstrip
1145+
actionStrip = fixture.componentInstance.actionStrip;
1146+
expect(actionStrip).toBeDefined();
1147+
expect(grid.actionStrip).toBeDefined();
1148+
1149+
// Verify that the outlet is properly set
1150+
expect(actionStrip.menuOverlaySettings.outlet).toBeDefined();
1151+
expect(actionStrip.menuOverlaySettings.outlet).toBe(grid.outlet);
1152+
});
1153+
});
11241154
});

projects/igniteui-angular/grids/grid/src/grid-base.directive.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4059,6 +4059,13 @@ export abstract class IgxGridBaseDirective implements GridType,
40594059
this.paginationComponents.changes.pipe(takeUntil(this.destroy$)).subscribe(() => {
40604060
this.setUpPaginator();
40614061
});
4062+
4063+
this.actionStripComponents.changes.pipe(takeUntil(this.destroy$)).subscribe(() => {
4064+
if (this.actionStrip) {
4065+
this.actionStrip.menuOverlaySettings.outlet = this.outlet;
4066+
}
4067+
});
4068+
40624069
if (this.actionStrip) {
40634070
this.actionStrip.menuOverlaySettings.outlet = this.outlet;
40644071
}

projects/igniteui-angular/test-utils/grid-samples.spec.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,6 +2419,54 @@ export class IgxAddRowComponent implements OnInit {
24192419
}
24202420
}
24212421

2422+
@Component({
2423+
template: `
2424+
<igx-grid #grid [data]="data" [width]="'800px'" [height]="'500px'"
2425+
[rowEditable]="true" [primaryKey]="'ID'">
2426+
@for (c of columns; track c.field) {
2427+
<igx-column [field]="c.field" [header]="c.field" [width]="c.width"></igx-column>
2428+
}
2429+
2430+
@if (showActionStrip) {
2431+
<igx-action-strip #actionStrip>
2432+
<igx-grid-editing-actions [addRow]='true'></igx-grid-editing-actions>
2433+
</igx-action-strip>
2434+
}
2435+
</igx-grid>
2436+
`,
2437+
imports: [
2438+
IgxGridComponent,
2439+
IgxColumnComponent,
2440+
IgxActionStripComponent,
2441+
IgxGridEditingActionsComponent
2442+
]
2443+
})
2444+
export class GridDynamicActionStripComponent implements OnInit {
2445+
@ViewChild('actionStrip', { read: IgxActionStripComponent })
2446+
public actionStrip: IgxActionStripComponent;
2447+
2448+
@ViewChild('grid', { read: IgxGridComponent, static: true })
2449+
public grid: IgxGridComponent;
2450+
2451+
public data: any[];
2452+
public columns: any[];
2453+
public showActionStrip = false;
2454+
2455+
public ngOnInit() {
2456+
this.columns = [
2457+
{ field: 'ID', width: '200px' },
2458+
{ field: 'CompanyName', width: '200px' },
2459+
{ field: 'ContactName', width: '200px' }
2460+
];
2461+
2462+
this.data = [
2463+
{ ID: 'ALFKI', CompanyName: 'Alfreds Futterkiste', ContactName: 'Maria Anders' },
2464+
{ ID: 'ANATR', CompanyName: 'Ana Trujillo Emparedados y helados', ContactName: 'Ana Trujillo' },
2465+
{ ID: 'ANTON', CompanyName: 'Antonio Moreno Taquería', ContactName: 'Antonio Moreno' }
2466+
];
2467+
}
2468+
}
2469+
24222470
@Component({
24232471
template: GridTemplateStrings.declareGrid(` [hideGroupedColumns]="true"`, '', ColumnDefinitions.exportGroupedDataColumns),
24242472
imports: [IgxGridComponent, IgxColumnComponent]

0 commit comments

Comments
 (0)