Skip to content

Commit 6ceb68d

Browse files
authored
Merge branch 'master' into BPenkov/IgxTextSelectionDirective-docs
2 parents 55ac4b1 + 7b25e62 commit 6ceb68d

File tree

9 files changed

+90
-50
lines changed

9 files changed

+90
-50
lines changed

projects/igniteui-angular/src/lib/combo/combo.component.spec.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,27 @@ describe('igxCombo', () => {
14811481
expectedOutput += ', ' + combo.data[9];
14821482
expect(inputElement.value).toEqual(expectedOutput);
14831483
}));
1484+
1485+
it('Should properly handle selection manipulation through onSelectionChange emit', fakeAsync(() => {
1486+
const fixture = TestBed.createComponent(IgxComboSampleComponent);
1487+
fixture.detectChanges();
1488+
const combo = fixture.componentInstance.combo;
1489+
// override selection
1490+
fixture.componentInstance.onSelectionChange = (event) => {
1491+
event.newSelection = [];
1492+
};
1493+
combo.toggle();
1494+
tick();
1495+
// No items are initially selected
1496+
expect(combo.selectedItems()).toEqual([]);
1497+
// Select the first 5 items
1498+
combo.selectItems(fixture.componentInstance.initData.splice(0, 5));
1499+
tick();
1500+
fixture.detectChanges();
1501+
tick();
1502+
// onSelectionChange fires and overrides the selection to be [];
1503+
expect(combo.selectedItems()).toEqual([]);
1504+
}));
14841505
});
14851506

14861507
describe('Rendering tests: ', () => {
@@ -3057,7 +3078,8 @@ class IgxComboScrollTestComponent {
30573078
@Component({
30583079
template: `
30593080
<igx-combo #combo [placeholder]="'Location'" [data]='items'
3060-
[filterable]='true' [valueKey]="'field'" [groupKey]="'region'" [width]="'400px'" [allowCustomValues]="true">
3081+
[filterable]='true' [valueKey]="'field'" [groupKey]="'region'" [width]="'400px'"
3082+
(onSelectionChange)="onSelectionChange($event)" [allowCustomValues]="true">
30613083
<ng-template #itemTemplate let-display let-key="valueKey">
30623084
<div class="state-card--simple">
30633085
<span class="small-red-circle"></span>

projects/igniteui-angular/src/lib/combo/combo.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,8 +1065,8 @@ export class IgxComboComponent implements AfterViewInit, ControlValueAccessor, O
10651065
const args: IComboSelectionChangeEventArgs = { oldSelection, newSelection };
10661066
this.onSelectionChange.emit(args);
10671067
newSelectionAsSet = new Set();
1068-
for (let i = 0; i < newSelection.length; i++) {
1069-
newSelectionAsSet.add(newSelection[i]);
1068+
for (let i = 0; i < args.newSelection.length; i++) {
1069+
newSelectionAsSet.add(args.newSelection[i]);
10701070
}
10711071
this.selectionAPI.set_selection(this.id, newSelectionAsSet);
10721072
this.value = this.dataType !== DataTypes.PRIMITIVE ?

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@
240240
@extend %igx-grid__group-expand-btn !optional;
241241
}
242242

243+
@include e(filtering-outlet) {
244+
@extend %igx-grid__filtering-outlet !optional;
245+
}
246+
243247
@for $i from 1 through 10 {
244248
@include e(row-indentation, $m: level-#{$i}) {
245249
@extend %igx-grid__row-indentation--level-#{$i} !optional;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,4 +1295,8 @@
12951295
padding-left: #{$i*map-get($grid-grouping-indicator-padding, 'compact')};
12961296
}
12971297
}
1298+
1299+
%igx-grid__filtering-outlet {
1300+
z-index: 99999;
1301+
}
12981302
}

projects/igniteui-angular/src/lib/grid/grid-filtering.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from '@angular/core';
1717
import { Subject, Subscription } from 'rxjs';
1818
import { DataType } from '../data-operations/data-util';
19-
import { IgxToggleDirective } from '../directives/toggle/toggle.directive';
19+
import { IgxToggleDirective, IgxOverlayOutletDirective } from '../directives/toggle/toggle.directive';
2020
import { IgxGridAPIService } from './api.service';
2121
import { IgxColumnComponent } from './column.component';
2222
import { FilteringExpressionsTree } from '../data-operations/filtering-expressions-tree';
@@ -248,6 +248,7 @@ export class IgxGridFilterComponent implements OnInit, OnDestroy, DoCheck {
248248
this._overlaySettings.positionStrategy.settings.horizontalStartPoint = HorizontalAlignment.Left;
249249
}
250250
this._overlaySettings.positionStrategy.settings.target = eventArgs.target;
251+
this._overlaySettings.outlet = grid.outletDirective;
251252
this.toggleDirective.toggle(this._overlaySettings);
252253
});
253254
}

projects/igniteui-angular/src/lib/grid/grid.component.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,5 @@
132132
<span class="igx-drop-area__text">{{dropAreaMessage}}</span>
133133
</ng-template>
134134

135+
<div class="igx-grid__filtering-outlet" igxOverlayOutlet></div>
136+

projects/igniteui-angular/src/lib/grid/grid.component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { IgxGridGroupByRowComponent } from './groupby-row.component';
5151
import { IgxGridRowComponent } from './row.component';
5252
import { DataUtil, IFilteringOperation, IFilteringExpressionsTree, FilteringExpressionsTree } from '../../public_api';
5353
import { IgxGridHeaderComponent } from './grid-header.component';
54+
import { IgxOverlayOutletDirective } from '../directives/toggle/toggle.directive';
5455

5556
let NEXT_ID = 0;
5657
const DEBOUNCE_TIME = 16;
@@ -1333,6 +1334,11 @@ export class IgxGridComponent implements OnInit, OnDestroy, AfterContentInit, Af
13331334
*/
13341335
@ViewChild('summaries')
13351336
public summaries: ElementRef;
1337+
/**
1338+
* @hidden
1339+
*/
1340+
@ViewChild(IgxOverlayOutletDirective, { read: IgxOverlayOutletDirective })
1341+
public outletDirective: IgxOverlayOutletDirective;
13361342

13371343
/**
13381344
* @hidden

projects/igniteui-angular/src/lib/navigation-drawer/navigation-drawer.component.spec.ts

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Component, DebugElement, ViewChild } from '@angular/core';
1010
import { By } from '@angular/platform-browser';
1111
import { Observable } from 'rxjs';
1212
import * as Infragistics from '../../public_api';
13+
import { wait } from '../test-utils/ui-interactions.spec';
1314

1415
// HammerJS simulator from https://github.com/hammerjs/simulator, manual typings TODO
1516
declare var Simulator: any;
@@ -475,7 +476,7 @@ describe('Navigation Drawer', () => {
475476
});
476477
}));
477478

478-
xit('should update pin based on window width (pinThreshold)', (done) => {
479+
it('should update pin based on window width (pinThreshold)', async (done) => {
479480
const template = `'<igx-nav-drawer [(pin)]="pin" [pinThreshold]="pinThreshold"></igx-nav-drawer>'`;
480481
let fixture: ComponentFixture<TestComponentPin>;
481482
TestBed.overrideComponent(TestComponentPin, {
@@ -484,49 +485,45 @@ describe('Navigation Drawer', () => {
484485
}});
485486

486487
// compile after overrides, not in before each: https://github.com/angular/angular/issues/10712
487-
TestBed.compileComponents().then(() => {
488-
fixture = TestBed.createComponent(TestComponentPin);
489-
expect(() => fixture.detectChanges()).not.toThrow();
490-
return fixture.whenStable();
491-
})
492-
.then(() => {
493-
494-
// defaults:
495-
expect(fixture.componentInstance.viewChild.pin).toBe(false, 'Should be initially unpinned');
496-
expect(fixture.componentInstance.pin).toBe(false, 'Parent component pin should update initially');
497-
498-
this.widthSpyOverride.and.returnValue(fixture.componentInstance.pinThreshold);
499-
window.dispatchEvent(new Event('resize'));
500-
// wait for debounce
501-
return new Promise((resolve) => {
502-
setTimeout(() => { resolve(); }, 200);
503-
});
504-
})
505-
.then(() => {
506-
expect(fixture.componentInstance.viewChild.pin).toBe(true, 'Should pin on window resize over threshold');
507-
expect(fixture.componentInstance.pin).toBe(true, 'Parent pin update on window resize over threshold');
508-
509-
this.widthSpyOverride.and.returnValue(768);
510-
window.dispatchEvent(new Event('resize'));
511-
// wait for debounce
512-
return new Promise((resolve) => {
513-
setTimeout(() => { resolve(); }, 200);
514-
});
515-
})
516-
.then(() => {
517-
expect(fixture.componentInstance.viewChild.pin).toBe(false, 'Should un-pin on window resize below threshold');
518-
expect(fixture.componentInstance.pin).toBe(false, 'Parent pin update on window resize below threshold');
519-
fixture.componentInstance.pinThreshold = 500;
520-
expect(() => fixture.detectChanges()).not.toThrow();
521-
return fixture.whenStable();
522-
})
523-
.then(() => {
524-
expect(fixture.componentInstance.viewChild.pin).toBe(true, 'Should re-pin on window resize over threshold');
525-
expect(fixture.componentInstance.pin).toBe(true, 'Parent pin update on re-pin');
526-
done();
527-
}).catch ((reason) => {
528-
return Promise.reject(reason);
529-
});
488+
await TestBed.compileComponents();
489+
fixture = TestBed.createComponent(TestComponentPin);
490+
// watch for initial pin with 2-way bind expression changed errors
491+
expect(() => fixture.detectChanges()).not.toThrow();
492+
await fixture.whenStable();
493+
// defaults:
494+
expect(fixture.componentInstance.viewChild.pin).toBe(false, 'Should be initially unpinned');
495+
expect(fixture.componentInstance.pin).toBe(false, 'Parent component pin should update initially');
496+
497+
// manual pin override
498+
fixture.componentInstance.pin = true;
499+
fixture.detectChanges();
500+
window.dispatchEvent(new Event('resize'));
501+
// wait for debounce
502+
await wait(200);
503+
expect(fixture.componentInstance.viewChild.pin).toBe(false, `Shouldn't change state on resize if window width is the same`);
504+
expect(fixture.componentInstance.pin).toBe(true, 'Parent component pin remain on resize if window width is the same');
505+
fixture.componentInstance.pin = true;
506+
fixture.detectChanges();
507+
508+
this.widthSpyOverride.and.returnValue(fixture.componentInstance.pinThreshold);
509+
window.dispatchEvent(new Event('resize'));
510+
// wait for debounce
511+
await wait(200);
512+
expect(fixture.componentInstance.viewChild.pin).toBe(true, 'Should pin on window resize over threshold');
513+
expect(fixture.componentInstance.pin).toBe(true, 'Parent pin update on window resize over threshold');
514+
515+
this.widthSpyOverride.and.returnValue(768);
516+
window.dispatchEvent(new Event('resize'));
517+
// wait for debounce
518+
await wait(200);
519+
expect(fixture.componentInstance.viewChild.pin).toBe(false, 'Should un-pin on window resize below threshold');
520+
expect(fixture.componentInstance.pin).toBe(false, 'Parent pin update on window resize below threshold');
521+
fixture.componentInstance.pinThreshold = 500;
522+
expect(() => fixture.detectChanges()).not.toThrow();
523+
await fixture.whenStable();
524+
expect(fixture.componentInstance.viewChild.pin).toBe(true, 'Should re-pin on window resize over threshold');
525+
expect(fixture.componentInstance.pin).toBe(true, 'Parent pin update on re-pin');
526+
done();
530527
});
531528

532529
it('should get correct window width', (done) => {

projects/igniteui-angular/src/lib/navigation-drawer/navigation-drawer.component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ export class IgxNavigationDrawerComponent implements
293293
}
294294

295295
private _gesturesAttached = false;
296-
private _widthCache: { width: number, miniWidth: number } = { width: null, miniWidth: null };
296+
private _widthCache: { width: number, miniWidth: number, windowWidth: number } = { width: null, miniWidth: null, windowWidth: null };
297297
private _resizeObserver: Subscription;
298298
private css: { [name: string]: string; } = {
299299
drawer: 'igx-nav-drawer__aside',
@@ -629,7 +629,7 @@ export class IgxNavigationDrawerComponent implements
629629
if (!this._resizeObserver) {
630630
this._resizeObserver = fromEvent(window, 'resize').pipe(debounce(() => interval(150)))
631631
.subscribe((value) => {
632-
this.checkPinThreshold();
632+
this.checkPinThreshold(value);
633633
});
634634
}
635635
}
@@ -647,6 +647,10 @@ export class IgxNavigationDrawerComponent implements
647647
let windowWidth;
648648
if (this.pinThreshold) {
649649
windowWidth = this.getWindowWidth();
650+
if (evt && this._widthCache.windowWidth === windowWidth) {
651+
return;
652+
}
653+
this._widthCache.windowWidth = windowWidth;
650654
if (!this.pin && windowWidth >= this.pinThreshold) {
651655
this.pin = true;
652656
this.pinChange.emit(true);

0 commit comments

Comments
 (0)