Skip to content

Commit e281186

Browse files
committed
fix(dropdown,select): add igxFor DI alias for tree-shaking
1 parent 3055cd8 commit e281186

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export class IgxComboDropDownComponent extends IgxDropDownComponent implements I
3636

3737
/** @hidden @internal */
3838
public override get scrollContainer(): HTMLElement {
39+
// TODO: Update, use public API if possible:
3940
return this.virtDir.dc.location.nativeElement;
4041
}
4142

projects/igniteui-angular/src/lib/directives/for-of/for_of.directive.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,36 @@ export class IgxForOfContext<T, U extends T[] = T[]> {
7979

8080
}
8181

82+
/** @hidden @internal */
83+
export abstract class IgxForOfToken<T, U extends T[] = T[]> {
84+
public abstract igxForOf: U & T[] | null;
85+
public abstract state: IForOfState;
86+
public abstract totalItemCount: number;
87+
public abstract scrollPosition: number;
88+
89+
public abstract chunkLoad: EventEmitter<IForOfState>;
90+
public abstract chunkPreload: EventEmitter<IForOfState>;
91+
92+
public abstract scrollTo(index: number): void;
93+
public abstract getScrollForIndex(index: number, bottom?: boolean): number;
94+
public abstract getScroll(): HTMLElement | undefined;
95+
96+
// TODO: Re-evaluate use for this internally, better expose through separate API
97+
public abstract igxForItemSize: any;
98+
public abstract igxForContainerSize: any;
99+
/** @hidden */
100+
public abstract dc: ComponentRef<any>
101+
}
102+
82103
@Directive({
83104
selector: '[igxFor][igxForOf]',
84-
providers: [IgxForOfScrollSyncService],
105+
providers: [
106+
IgxForOfScrollSyncService,
107+
{ provide: IgxForOfToken, useExisting: IgxForOfDirective }
108+
],
85109
standalone: true
86110
})
87-
// eslint-disable @angular-eslint/no-conflicting-lifecycle
88-
export class IgxForOfDirective<T, U extends T[] = T[]> implements OnInit, OnChanges, DoCheck, OnDestroy, AfterViewInit {
111+
export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U> implements OnInit, OnChanges, DoCheck, OnDestroy, AfterViewInit {
89112

90113
/**
91114
* An @Input property that sets the data to be rendered.
@@ -383,7 +406,9 @@ export class IgxForOfDirective<T, U extends T[] = T[]> implements OnInit, OnChan
383406
protected platformUtil: PlatformUtil,
384407
@Inject(DOCUMENT)
385408
protected document: any,
386-
) { }
409+
) {
410+
super();
411+
}
387412

388413
public verticalScrollHandler(event) {
389414
this.onScroll(event);
@@ -604,7 +629,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> implements OnInit, OnChan
604629
*
605630
* @param index
606631
*/
607-
public scrollTo(index) {
632+
public scrollTo(index: number) {
608633
if (index < 0 || index > (this.isRemote ? this.totalItemCount : this.igxForOf.length) - 1) {
609634
return;
610635
}

projects/igniteui-angular/src/lib/drop-down/drop-down.component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { IBaseCancelableBrowserEventArgs, IBaseEventArgs } from '../core/utils';
2828
import { IgxSelectionAPIService } from '../core/selection';
2929
import { Subject } from 'rxjs';
3030
import { IgxDropDownItemBaseDirective } from './drop-down-item.base';
31-
import { IgxForOfDirective } from '../directives/for-of/for_of.directive';
31+
import { IgxForOfToken } from '../directives/for-of/for_of.directive';
3232
import { take } from 'rxjs/operators';
3333
import { DisplayDensityToken, IDisplayDensityOptions } from '../core/density';
3434
import { OverlaySettings } from '../services/overlay/utilities';
@@ -135,8 +135,8 @@ export class IgxDropDownComponent extends IgxDropDownBaseDirective implements ID
135135
@Input()
136136
public labelledBy: string;
137137

138-
@ContentChild(IgxForOfDirective, { read: IgxForOfDirective })
139-
protected virtDir: IgxForOfDirective<any>;
138+
@ContentChild(IgxForOfToken)
139+
protected virtDir: IgxForOfToken<any>;
140140

141141
@ViewChild(IgxToggleDirective, { static: true })
142142
protected toggleDirective: IgxToggleDirective;
@@ -343,6 +343,7 @@ export class IgxDropDownComponent extends IgxDropDownBaseDirective implements ID
343343
return;
344344
}
345345
let targetScroll = this.virtDir.getScrollForIndex(this.selectedItem.index);
346+
// TODO: This logic _cannot_ be right, those are optional user-provided inputs that can be strings with units, refactor:
346347
const itemsInView = this.virtDir.igxForContainerSize / this.virtDir.igxForItemSize;
347348
targetScroll -= (itemsInView / 2 - 1) * this.virtDir.igxForItemSize;
348349
this.virtDir.getScroll().scrollTop = targetScroll;

projects/igniteui-angular/src/public_api.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ export * from './lib/directives/drag-drop/public_api';
1919
export * from './lib/directives/filter/filter.directive';
2020
export * from './lib/directives/focus/focus.directive';
2121
export * from './lib/directives/focus-trap/focus-trap.directive';
22-
export * from './lib/directives/for-of/for_of.directive';
22+
export {
23+
IgxForOfContext, IgxForOfDirective, IForOfState, IgxGridForOfContext, IgxGridForOfDirective
24+
} from './lib/directives/for-of/for_of.directive';
2325
export * from './lib/directives/layout/layout.directive';
2426
export * from './lib/directives/mask/mask.directive';
2527
export * from './lib/directives/radio/public_api';

0 commit comments

Comments
 (0)