Skip to content

Commit f487c90

Browse files
georgianastasovdkamburovteodosiahmddragnevkdinev
authored
fix(action-strip): Hide action strip on mouse leave event of row (#12204)
* fix(action-strip): Hide action strip on mouse leave event of row * fix(action-strip): Fix added test that checks auto-hide on the mouse leave event * fix(action-strip): Boolean to hide or not the action strip if it is a menu * fix(action-strip): Fix closing curly brace * fix(action-strip): Fix test for hide on mouse leave and add one for boolean flag * fix(action-strip): Change boolean getter logic Co-authored-by: Deyan Kamburov <[email protected]> Co-authored-by: Teodosia Hristodorova <[email protected]> Co-authored-by: Martin Dragnev <[email protected]> Co-authored-by: Konstantin Dinev <[email protected]> Co-authored-by: Stamen Stoychev <[email protected]>
1 parent ce20956 commit f487c90

File tree

3 files changed

+113
-1
lines changed

3 files changed

+113
-1
lines changed

projects/igniteui-angular/src/lib/action-strip/action-strip.component.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,24 @@ export class IgxActionStripComponent extends DisplayDensityBase implements After
134134
return this._resourceStrings;
135135
}
136136

137+
/**
138+
* Hide or not the Action Strip based on if it is a menu.
139+
*
140+
* @hidden
141+
* @internal
142+
*/
143+
public get hideOnRowLeave(): boolean{
144+
if(this.menu.items.length === 0){
145+
return true;
146+
}else if(this.menu.items.length > 0){
147+
if(this.menu.collapsed){
148+
return true;
149+
}else{
150+
return false;
151+
}
152+
}
153+
}
154+
137155
/**
138156
* Reference to the menu
139157
*

projects/igniteui-angular/src/lib/action-strip/grid-actions/grid-editing-actions.component.spec.ts

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ describe('igxGridEditingActions #grid ', () => {
2929
IgxActionStripPinEditComponent,
3030
IgxActionStripEditMenuComponent,
3131
IgxHierarchicalGridActionStripComponent,
32-
IgxTreeGridEditActionsComponent
32+
IgxTreeGridEditActionsComponent,
33+
IgxActionStripOneRowComponent,
34+
IgxActionStripMenuOneRowComponent
3335
],
3436
imports: [
3537
NoopAnimationsModule,
@@ -153,6 +155,28 @@ describe('igxGridEditingActions #grid ', () => {
153155

154156
expect(grid.rowList.first.data['ID']).toBe('ANATR');
155157
});
158+
it('should not auto-hide on mouse leave of row if action strip is menu', () => {
159+
fixture = TestBed.createComponent(IgxActionStripMenuOneRowComponent);
160+
fixture.detectChanges();
161+
actionStrip = fixture.componentInstance.actionStrip;
162+
grid = fixture.componentInstance.grid;
163+
164+
const row = grid.getRowByIndex(0);
165+
row.pin();
166+
const rowElem = grid.pinnedRows[0];
167+
row.unpin();
168+
169+
actionStrip.show(row);
170+
fixture.detectChanges();
171+
172+
actionStrip.menu.open();
173+
fixture.detectChanges();
174+
175+
UIInteractions.simulateMouseEvent('mouseleave', rowElem.element.nativeElement, 0, 200);
176+
fixture.detectChanges();
177+
178+
expect(actionStrip.hidden).toBeFalse();
179+
});
156180
});
157181

158182
describe('integration with pinning actions ', () => {
@@ -191,6 +215,25 @@ describe('igxGridEditingActions #grid ', () => {
191215
expect(actionStrip.context).toBe(row);
192216
expect(actionStrip.hidden).toBeFalse();
193217
});
218+
it('should auto-hide on mouse leave of row.', async () => {
219+
fixture = TestBed.createComponent(IgxActionStripOneRowComponent);
220+
fixture.detectChanges();
221+
actionStrip = fixture.componentInstance.actionStrip;
222+
grid = fixture.componentInstance.grid;
223+
224+
const row = grid.getRowByIndex(0);
225+
row.pin();
226+
const rowElem = grid.pinnedRows[0];
227+
228+
actionStrip.show(row);
229+
fixture.detectChanges();
230+
231+
expect(actionStrip.hidden).toBeFalse();
232+
UIInteractions.simulateMouseEvent('mouseleave', rowElem.element.nativeElement, 0, 200);
233+
fixture.detectChanges();
234+
235+
expect(actionStrip.hidden).toBeTrue();
236+
});
194237
it('should auto-hide on mouse leave of grid.', () => {
195238
const row = grid.getRowByIndex(0);
196239
actionStrip.show(row);
@@ -329,6 +372,7 @@ class IgxActionStripTestingComponent implements OnInit {
329372
public grid: IgxGridComponent;
330373

331374
private data: any[];
375+
private dataOneRow: any[];
332376
private columns: any[];
333377

334378
public ngOnInit() {
@@ -377,6 +421,10 @@ class IgxActionStripTestingComponent implements OnInit {
377421
{ ID: 'FRANS', CompanyName: 'Franchi S.p.A.', ContactName: 'Paolo Accorti', ContactTitle: 'Sales Representative', Address: 'Via Monte Bianco 34', City: 'Torino', Region: null, PostalCode: '10100', Country: 'Italy', Phone: '011-4988260', Fax: '011-4988261' }
378422
];
379423
/* eslint-enable max-len */
424+
425+
this.dataOneRow = [
426+
{ ID: 'ALFKI', CompanyName: 'Alfreds Futterkiste', ContactName: 'Maria Anders', ContactTitle: 'Sales Representative', Address: 'Obere Str. 57', City: 'Berlin', Region: null, PostalCode: '12209', Country: 'Germany', Phone: '030-0074321', Fax: '030-0076545' },
427+
];
380428
}
381429
}
382430

@@ -414,3 +462,38 @@ class IgxActionStripPinEditComponent extends IgxActionStripTestingComponent {
414462
})
415463
class IgxActionStripEditMenuComponent extends IgxActionStripTestingComponent {
416464
}
465+
466+
@Component({
467+
template: `
468+
<igx-grid #grid [data]="dataOneRow" [width]="'800px'" [height]="'500px'"
469+
[rowEditable]="true" [primaryKey]="'ID'">
470+
<igx-column *ngFor="let c of columns" [sortable]="true" [field]="c.field" [header]="c.field"
471+
[width]="c.width" [pinned]='c.pinned' [hidden]='c.hidden'>
472+
</igx-column>
473+
474+
<igx-action-strip #actionStrip>
475+
<igx-grid-pinning-actions></igx-grid-pinning-actions>
476+
<igx-grid-editing-actions></igx-grid-editing-actions>
477+
</igx-action-strip>
478+
</igx-grid>
479+
`
480+
})
481+
class IgxActionStripOneRowComponent extends IgxActionStripTestingComponent {
482+
}
483+
484+
@Component({
485+
template: `
486+
<igx-grid #grid [data]="dataOneRow" [width]="'800px'" [height]="'500px'"
487+
[rowEditable]="true" [primaryKey]="'ID'">
488+
<igx-column *ngFor="let c of columns" [sortable]="true" [field]="c.field" [header]="c.field"
489+
[width]="c.width" [pinned]='c.pinned' [hidden]='c.hidden'>
490+
</igx-column>
491+
492+
<igx-action-strip #actionStrip>
493+
<igx-grid-editing-actions [asMenuItems]='true'></igx-grid-editing-actions>
494+
</igx-action-strip>
495+
</igx-grid>
496+
`
497+
})
498+
class IgxActionStripMenuOneRowComponent extends IgxActionStripTestingComponent {
499+
}

projects/igniteui-angular/src/lib/grids/row.directive.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,17 @@ export class IgxRowDirective implements DoCheck, AfterViewInit, OnDestroy {
413413
}
414414
}
415415

416+
/**
417+
* @hidden
418+
* @internal
419+
*/
420+
@HostListener('mouseleave')
421+
public hideActionStrip() {
422+
if (this.grid.actionStrip && this.grid.actionStrip.hideOnRowLeave) {
423+
this.grid.actionStrip.hide();
424+
}
425+
}
426+
416427
/**
417428
* @hidden
418429
* @internal

0 commit comments

Comments
 (0)