Skip to content

Commit 7c4a80c

Browse files
authored
fix(grid): fix grid loading indicator position (#16952)
1 parent 4ee5c3f commit 7c4a80c

3 files changed

Lines changed: 36 additions & 20 deletions

File tree

projects/igniteui-angular/core/src/core/styles/components/grid/_grid-theme.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2341,7 +2341,10 @@
23412341
}
23422342

23432343
%igx-grid__loading-outlet {
2344-
z-index: 10003;
2344+
width: 100%;
2345+
height: 100%;
2346+
z-index: -1;
2347+
position: absolute;
23452348

23462349
> %overlay-wrapper--modal {
23472350
background: none;

projects/igniteui-angular/grids/grid/src/grid.component.spec.ts

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -442,48 +442,54 @@ describe('IgxGrid Component Tests #grid', () => {
442442

443443
const grid = fixture.componentInstance.grid;
444444
const gridElement = fixture.debugElement.query(By.css('.igx-grid'));
445-
const gridBody = fixture.debugElement.query(By.css(TBODY_CLASS));
446-
let loadingIndicator = gridBody.query(By.css('.igx-grid__loading'));
445+
const gridBodyContent = fixture.debugElement.query(By.css(TBODY_CLASS));
446+
let loadingIndicator = gridBodyContent.query(By.css('.igx-grid__loading'));
447447

448448
expect(loadingIndicator).not.toBeNull();
449-
expect(gridBody.nativeElement.textContent).not.toEqual(grid.emptyFilteredGridMessage);
449+
expect(gridBodyContent.nativeElement.textContent).not.toEqual(grid.emptyFilteredGridMessage);
450450

451451
// Check for loaded rows in grid's container
452452
fixture.componentInstance.generateData(30);
453453
fixture.detectChanges();
454454
tick(1000);
455-
expect(parseInt(window.getComputedStyle(gridBody.nativeElement).height, 10)).toBeGreaterThan(300);
455+
expect(parseInt(window.getComputedStyle(gridBodyContent.nativeElement).height, 10)).toBeGreaterThan(300);
456456

457-
loadingIndicator = gridBody.query(By.css('.igx-grid__loading'));
457+
loadingIndicator = gridBodyContent.query(By.css('.igx-grid__loading'));
458458
expect(loadingIndicator).toBeNull();
459459

460-
// the overlay should be shown
460+
// the overlay should be shown and container should have the same dimensions as the grid's body
461461
loadingIndicator = gridElement.query(By.css('.igx-grid__loading-outlet'));
462+
const gridBody = fixture.debugElement.query(By.css('.igx-grid__tbody'));
463+
expect(loadingIndicator.nativeElement.offsetWidth).toBe(gridBody.nativeElement.offsetWidth);
464+
expect(loadingIndicator.nativeElement.offsetHeight).toBe(gridBody.nativeElement.offsetHeight);
465+
462466
expect(loadingIndicator.nativeElement.children.length).not.toBe(0);
463467

464468
// Check for empty filter grid message and body less than 100px
465469
const columns = fixture.componentInstance.grid.columnList;
466470
grid.filter(columns.get(0).field, 546000, IgxNumberFilteringOperand.instance().condition('equals'));
467471
fixture.detectChanges();
468472
tick(100);
469-
expect(gridBody.nativeElement.textContent).not.toEqual(grid.emptyFilteredGridMessage);
473+
expect(gridBodyContent.nativeElement.textContent).not.toEqual(grid.emptyFilteredGridMessage);
470474

471475
// Clear filter and check if grid's body height is restored based on all loaded rows
472476
grid.clearFilter(columns.get(0).field);
473477
fixture.detectChanges();
474478
tick(100);
475-
expect(parseInt(window.getComputedStyle(gridBody.nativeElement).height, 10)).toBeGreaterThan(300);
479+
expect(parseInt(window.getComputedStyle(gridBodyContent.nativeElement).height, 10)).toBeGreaterThan(300);
476480

477481
// Clearing grid's data and check for empty grid message
478482
fixture.componentInstance.clearData();
479483
fixture.detectChanges();
480484
tick(100);
481485

482-
loadingIndicator = gridBody.query(By.css('.igx-grid__loading'));
486+
loadingIndicator = gridBodyContent.query(By.css('.igx-grid__loading'));
483487
expect(loadingIndicator).not.toBeNull();
484488

485-
// the overlay should be hidden
489+
// the overlay should be hidden and container should have the same dimensions as the grid's body
486490
loadingIndicator = gridElement.query(By.css('.igx-grid__loading-outlet'));
491+
expect(loadingIndicator.nativeElement.offsetWidth).toBe(gridBody.nativeElement.offsetWidth);
492+
expect(loadingIndicator.nativeElement.offsetHeight).toBe(gridBody.nativeElement.offsetHeight);
487493
expect(loadingIndicator.nativeElement.children.length).toBe(0);
488494
}));
489495

@@ -618,23 +624,26 @@ describe('IgxGrid Component Tests #grid', () => {
618624

619625
const grid = fixture.componentInstance.grid;
620626
const gridElement = fixture.debugElement.query(By.css('.igx-grid'));
621-
const gridBody = fixture.debugElement.query(By.css(TBODY_CLASS));
622-
let loadingIndicator = gridBody.query(By.css('.igx-grid__loading'));
627+
const gridBodyContent = fixture.debugElement.query(By.css(TBODY_CLASS));
628+
let loadingIndicator = gridBodyContent.query(By.css('.igx-grid__loading'));
623629

624630
expect(loadingIndicator).not.toBeNull();
625-
expect(gridBody.nativeElement.textContent).not.toEqual(grid.emptyFilteredGridMessage);
631+
expect(gridBodyContent.nativeElement.textContent).not.toEqual(grid.emptyFilteredGridMessage);
626632

627633
// Check for loaded rows in grid's container
628634
fixture.componentInstance.generateData(30);
629635
fixture.detectChanges();
630636
tick(1000);
631-
expect(parseInt(window.getComputedStyle(gridBody.nativeElement).height, 10)).toBe(548);
637+
expect(parseInt(window.getComputedStyle(gridBodyContent.nativeElement).height, 10)).toBe(548);
632638

633-
loadingIndicator = gridBody.query(By.css('.igx-grid__loading'));
639+
loadingIndicator = gridBodyContent.query(By.css('.igx-grid__loading'));
634640
expect(loadingIndicator).toBeNull();
635641

636-
// the overlay should be shown
642+
// the overlay should be shown and container should have the same dimensions as the grid's body
637643
loadingIndicator = gridElement.query(By.css('.igx-grid__loading-outlet'));
644+
const gridBody = fixture.debugElement.query(By.css('.igx-grid__tbody'));
645+
expect(loadingIndicator.nativeElement.offsetWidth).toBe(gridBody.nativeElement.offsetWidth);
646+
expect(loadingIndicator.nativeElement.offsetHeight).toBe(gridBody.nativeElement.offsetHeight);
638647
expect(loadingIndicator.nativeElement.children.length).not.toBe(0);
639648

640649
grid.isLoading = false;
@@ -647,10 +656,10 @@ describe('IgxGrid Component Tests #grid', () => {
647656
tick(100);
648657

649658
// isLoading is still false so the empty data message should show, not the loading indicator
650-
loadingIndicator = gridBody.query(By.css('.igx-grid__loading'));
659+
loadingIndicator = gridBodyContent.query(By.css('.igx-grid__loading'));
651660
expect(loadingIndicator).toBeNull();
652661

653-
expect(gridBody.nativeElement.textContent).toEqual(grid.emptyGridMessage);
662+
expect(gridBodyContent.nativeElement.textContent).toEqual(grid.emptyGridMessage);
654663
}));
655664

656665
it('should render empty message when grid height is 100%', fakeAsync(() => {

projects/igniteui-angular/grids/hierarchical-grid/src/hierarchical-grid.integration.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,11 @@ describe('IgxHierarchicalGrid Integration #hGrid', () => {
441441

442442
const gridHeight = childGrid.nativeElement.offsetHeight;
443443
const childElements: HTMLElement[] = Array.from(childGrid.nativeElement.children) as HTMLElement [];
444-
const elementsHeight = childElements.map(elem => elem.offsetHeight).reduce((total, height) => total + height, 0);
444+
const elementsHeight = childElements
445+
// skip the loading outlet element as it is positioned absolute and doesn't take part in the height calculation of the grid
446+
.filter(elem => !elem.className.includes('igx-grid__loading-outlet'))
447+
.map(elem => elem.offsetHeight)
448+
.reduce((total, height) => total + height, 0);
445449

446450
// Expect the combined height of all elements (header, body, footer etc) to equal the calculated height of the grid.
447451
expect(elementsHeight).toEqual(gridHeight);

0 commit comments

Comments
 (0)