Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ All notable changes for each version of this project will be documented in this
- In Safari, the horizontal scrollbar of a horizontally virtualized `igxFor` is now visible and usable when the list first renders. Previously it was collapsed until change detection ran again.
- `IgxGridComponent`, `IgxTreeGridComponent`, `IgxHierarchicalGridComponent`
- Auto-sizing columns with `width="auto"` no longer throws when a column group is partly scrolled out of view and one of its child columns with a cell template has no rendered cells. Such a column is now measured when it is scrolled into view.
- `IgxGridComponent`, `IgxTreeGridComponent`, `IgxHierarchicalGridComponent`, `IgxPivotGridComponent`
- In a shadow root, such as the shadow root of a component with `ViewEncapsulation.ShadowDom` or of a custom element, vertical scrolling and the filter row now work. Previously, in a grid that renders more than 100 cells, each scroll threw `Cannot read properties of null (reading 'scrollTop')` and the rows did not follow the scrollbar. Text typed in the filter row threw an error and did not filter the grid (#17860).
- `provideIgniteIntl()`
- The US time zone abbreviations `UT`, `EDT`, `CST`, `CDT`, `MDT`, `PST` and `PDT`, in any letter case, are formatted with fixed offsets, as with the Angular date pipe. This applies to date formatting such as `IColumnPipeArgs.timezone` and the date pipe. A format that shows the zone shows the offset, such as `GMT-8` for `PST`. Previously `UT`, `EDT`, `CDT`, `MDT` and `PDT` produced the unformatted date text, and `CST` and `PST` were shifted by daylight saving time. `EST` and `MST` are formatted as before (#18031).
- `IgxMaskDirective`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -967,12 +967,14 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
* @hidden
* Function that is called when scrolling vertically
*/
protected onScroll(event) {
protected onScroll(_event) {
/* in certain situations this may be called when no scrollbar is visible */
if (!parseFloat(this.scrollComponent.nativeElement.style.height)) {
return;
}
this.scrollComponent.scrollAmount = event.target.scrollTop;
// Read the scroll element, not the event target: the grid handles the event after a throttle, when the
// browser has cleared the target of an event in a shadow tree.
this.scrollComponent.scrollAmount = this.scrollComponent.nativeElement.scrollTop;
if (!this._bScrollInternal) {
this._calcVirtualScrollPosition(this.scrollComponent.scrollAmount);
} else {
Expand Down Expand Up @@ -1174,13 +1176,14 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
* @hidden
* Function that is called when scrolling horizontally
*/
protected onHScroll(event) {
protected onHScroll(_event) {
/* in certain situations this may be called when no scrollbar is visible */
const firstScrollChild = this.scrollComponent.nativeElement.children.item(0) as HTMLElement;
if (!parseFloat(firstScrollChild.style.width)) {
return;
}
this.scrollComponent.scrollAmount = event.target.scrollLeft;
// Read the scroll element, not the event target, which the browser clears after the dispatch in a shadow tree.
this.scrollComponent.scrollAmount = this.scrollComponent.nativeElement.scrollLeft;
if (!this._bScrollInternal) {
this._calcVirtualScrollPosition(this.scrollComponent.scrollAmount);
} else {
Expand Down Expand Up @@ -1843,8 +1846,10 @@ export class IgxGridForOfDirective<T, U extends T[] = T[]> extends IgxForOfDirec
}
}

public override onScroll(event) {
this.scrollComponent.scrollAmount = event.target.scrollTop;
public override onScroll(_event) {
// Read the scroll element, not the event target: the grid handles the event after a throttle, when the
// browser has cleared the target of an event in a shadow tree.
this.scrollComponent.scrollAmount = this.scrollComponent.nativeElement.scrollTop;
if (!this.scrollComponent.size) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,15 @@ export class IgxGridFilteringRowComponent implements OnInit, AfterViewInit, OnDe
return;
}

// The 'iskeyPressed' flag is needed for a case in IE, because the input event is fired on focus and for some reason,
// when you have a japanese character as a placeholder, on init the value here is empty string .
const target = eventArgs.target;
if (this.column.dataType === GridColumnDataType.DateTime) {
this.value = eventArgs;
return;
}
// The 'iskeyPressed' flag is needed for a case in IE, because the input event is fired on focus and for some reason,
// when you have a japanese character as a placeholder, on init the value here is empty string .
// Read the input, not the event target: the debounced call runs after the dispatch, when the browser
// has cleared the target of an event in a shadow tree.
const target = this.input.nativeElement;
if (this.platform.isEdge && target.type !== 'number'
|| this.isKeyPressed || target.value || target.checkValidity()) {
this.value = target.value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import {
IgxGridDatesFilteringComponent,
LoadOnDemandFilterStrategy,
IgxGridFilteringNumericComponent,
IgxGridConditionalFilteringComponent
IgxGridConditionalFilteringComponent,
IgxGridInShadowRootComponent
} from '../../../test-utils/grid-samples.spec';
import { GridSelectionMode, FilterMode } from 'igniteui-angular/grids/core';
import { ControlsFunction } from '../../../test-utils/controls-functions.spec';
Expand Down Expand Up @@ -3247,6 +3248,32 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
closeChipFromFilteringUIRow(fix, grid, 'ReleaseTime', 4);
}));
});

describe('in a shadow root', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [IgxGridInShadowRootComponent],
providers: [{ provide: INPUT_DEBOUNCE_TIME, useValue: 0 }]
}).compileComponents();
}));

it('should filter by the value typed in the filter row', async () => {
const fix = TestBed.createComponent(IgxGridInShadowRootComponent);
fix.detectChanges();
const grid = fix.componentInstance.grid;
expect(grid.nativeElement.getRootNode()).toBe(fix.nativeElement.shadowRoot);

GridFunctions.clickFilterCellChip(fix, 'Col0');
// The filter row handles the input after a debounce. The browser clears the target of
// an event in a shadow tree when the dispatch ends.
GridFunctions.typeValueInFilterRowInput('r1c0', fix);
await wait(16);
fix.detectChanges();

expect(grid.dataView.length).toBe(1);
expect(grid.dataView[0].ID).toBe(1);
});
});
});

describe('IgxGrid - Filtering actions - Excel style filtering #grid', () => {
Expand Down
58 changes: 53 additions & 5 deletions projects/igniteui-angular/grids/grid/src/grid.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { IForOfState } from 'igniteui-angular/directives';
import { GridTemplateStrings } from '../../../test-utils/template-strings.spec';
import { SampleTestData } from '../../../test-utils/sample-test-data.spec';
import { BasicGridComponent } from '../../../test-utils/grid-base-components.spec';
import { IgxGridInShadowRootComponent } from '../../../test-utils/grid-samples.spec';
import { UIInteractions, wait } from '../../../test-utils/ui-interactions.spec';
import { GridSelectionMode } from 'igniteui-angular/grids/core';
import { IgxTabContentComponent, IgxTabHeaderComponent, IgxTabItemComponent, IgxTabsComponent } from 'igniteui-angular/tabs';
Expand Down Expand Up @@ -943,6 +944,20 @@ describe('IgxGrid Component Tests #grid', () => {
}));

// Drive scrollNotify directly (not programmatic scrollTop, whose async native events would mask a dropped-trailing regression) to exercise the throttle window deterministically.
// The grid reads the position from its scroll element when the throttled call runs, so stub scrollTop on the element instead of scrolling it.
const stubScrollTop = (scrollEl: HTMLElement) => {
let scrollTop = scrollEl.scrollTop;
Object.defineProperty(scrollEl, 'scrollTop', {
configurable: true,
get: () => scrollTop,
set: (value: number) => scrollTop = value
});
return (grid: IgxGridComponent, value: number) => {
scrollTop = value;
grid.scrollNotify.next(new Event('scroll'));
};
};

it('should settle at the top row after a fast momentum scroll back to scrollTop 0', async () => {
const fix = TestBed.createComponent(IgxGridScrollThrottleComponent);
fix.detectChanges();
Expand All @@ -953,19 +968,20 @@ describe('IgxGrid Component Tests #grid', () => {
const scrollEl = virtDir.getScroll();
const hScroll = grid.headerContainer.getScroll();
const maxScroll = scrollEl.scrollHeight - scrollEl.clientHeight;
const scrollTo = stubScrollTop(scrollEl);

// Guard the reproduction condition: the fixture must overflow horizontally.
expect(hScroll.scrollWidth).toBeGreaterThan(hScroll.clientWidth);

// Move away from the top so the first rows are virtualized out of view.
grid.scrollNotify.next({ target: { scrollTop: maxScroll } });
scrollTo(grid, maxScroll);
await wait(50);
fix.detectChanges();
expect(virtDir.state.startIndex).toBeGreaterThan(0);

// Momentum scroll back to top: intermediate on the leading edge, scrollTop = 0 settle only on the trailing edge.
grid.scrollNotify.next({ target: { scrollTop: Math.round(maxScroll / 2) } });
grid.scrollNotify.next({ target: { scrollTop: 0 } });
scrollTo(grid, Math.round(maxScroll / 2));
scrollTo(grid, 0);
await wait(50);
fix.detectChanges();

Expand All @@ -985,13 +1001,14 @@ describe('IgxGrid Component Tests #grid', () => {
const hScroll = grid.headerContainer.getScroll();
const maxScroll = scrollEl.scrollHeight - scrollEl.clientHeight;
const lastIndex = fix.componentInstance.data.length - 1;
const scrollTo = stubScrollTop(scrollEl);

expect(hScroll.scrollWidth).toBeGreaterThan(hScroll.clientWidth);
expect(virtDir.state.startIndex).toBe(0);

// Momentum scroll top to bottom: intermediate on the leading edge, max-scroll settle only on the trailing edge.
grid.scrollNotify.next({ target: { scrollTop: Math.round(maxScroll / 2) } });
grid.scrollNotify.next({ target: { scrollTop: maxScroll } });
scrollTo(grid, Math.round(maxScroll / 2));
scrollTo(grid, maxScroll);
await wait(50);
fix.detectChanges();

Expand All @@ -1000,6 +1017,37 @@ describe('IgxGrid Component Tests #grid', () => {
expect(grid.gridAPI.get_row_by_index(lastIndex)).toBeDefined();
});
});

describe('in a shadow root', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [NoopAnimationsModule, IgxGridInShadowRootComponent]
}).compileComponents();
}));

it('should scroll to the last position of a throttled scroll', async () => {
const fix = TestBed.createComponent(IgxGridInShadowRootComponent);
fix.detectChanges();
await wait(50);
fix.detectChanges();
const grid = fix.componentInstance.grid;
const scroll = grid.verticalScrollContainer.getScroll();
expect(scroll.getRootNode()).toBe(fix.nativeElement.shadowRoot);
// The grid throttles the vertical scroll by up to 60ms, depending on the number of rendered cells.
(grid as any).throttleTime$.next(60);

// The first scroll event is handled while it is dispatched, the second one when the throttle ends.
// The browser clears the target of an event in a shadow tree when the dispatch ends.
scroll.scrollTop = grid.renderedRowHeight * 10;
await wait(16);
scroll.scrollTop = grid.renderedRowHeight * 50;
await wait(16);
await wait(100);
fix.detectChanges();

expect(grid.verticalScrollContainer.state.startIndex).toBe(50);
});
});
});

describe('IgxGrid - default rendering for rows and columns', () => {
Expand Down
46 changes: 45 additions & 1 deletion projects/igniteui-angular/test-utils/grid-samples.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, TemplateRef, ViewChild, Input, AfterViewInit, QueryList, ViewChildren, OnInit } from '@angular/core';
import { Component, TemplateRef, ViewChild, Input, AfterViewInit, QueryList, ViewChildren, OnInit, ViewEncapsulation, ElementRef, inject } from '@angular/core';

import {
BasicGridComponent, BasicGridSearchComponent, GridAutoGenerateComponent,
Expand Down Expand Up @@ -2895,3 +2895,47 @@ export class CollapsibleGroupWithExplicitChildWidthsComponent {
public grid: IgxGridComponent;
public data = SampleTestData.contactInfoDataFull();
}

/**
* Renders the grid in the open shadow root of the component, inside `@if`.
* The styles of the page, including the theme, are copied to the shadow root, as an application adds its theme there.
*/
@Component({
selector: 'igx-grid-shadow-root',
template: `
@if (showGrid) {
<igx-grid #grid [data]="data" height="300px" width="600px" [autoGenerate]="true" [allowFiltering]="true"></igx-grid>
}`,
encapsulation: ViewEncapsulation.ShadowDom,
imports: [IgxGridComponent]
})
export class IgxGridInShadowRootComponent {
@ViewChild(IgxGridComponent)
public grid: IgxGridComponent;
public showGrid = true;
public data = Array.from({ length: 200 }, (_row, rowIndex) => {
const record: Record<string, number | string> = { ID: rowIndex };
for (let col = 0; col < 10; col++) {
record[`Col${col}`] = `r${rowIndex}c${col}`;
}
return record;
});

constructor() {
const root = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement.shadowRoot;
const sheets: CSSStyleSheet[] = [];
for (const sheet of Array.from(document.styleSheets)) {
let rules: CSSRuleList;
try {
rules = sheet.cssRules;
} catch {
// The rules of a stylesheet from another origin, such as a font, cannot be read.
continue;
}
const copy = new CSSStyleSheet();
copy.replaceSync(Array.from(rules, rule => rule.cssText).join('\n'));
sheets.push(copy);
}
root.adoptedStyleSheets = [...sheets, ...root.adoptedStyleSheets];
}
}
Loading