-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(*): Remove the need of hardcoded item heights in combo #14871
base: master
Are you sure you want to change the base?
Changes from 1 commit
7b9d9fc
54ca89e
728d38d
b6988e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -45,8 +45,8 @@ import { IComboItemAdditionEvent, IComboSearchInputEventArgs } from './public_ap | |||||||||
import { ComboResourceStringsEN, IComboResourceStrings } from '../core/i18n/combo-resources'; | ||||||||||
import { getCurrentResourceStrings } from '../core/i18n/resources'; | ||||||||||
import { DOCUMENT } from '@angular/common'; | ||||||||||
import { Size } from '../grids/common/enums'; | ||||||||||
import { isEqual } from 'lodash-es'; | ||||||||||
import { ToggleViewEventArgs } from '../directives/toggle/toggle.directive'; | ||||||||||
|
||||||||||
export const IGX_COMBO_COMPONENT = /*@__PURE__*/new InjectionToken<IgxComboBase>('IgxComboComponentToken'); | ||||||||||
|
||||||||||
|
@@ -82,19 +82,6 @@ export interface IgxComboBase { | |||||||||
|
||||||||||
let NEXT_ID = 0; | ||||||||||
|
||||||||||
/** | ||||||||||
* @hidden | ||||||||||
* The default number of items that should be in the combo's | ||||||||||
* drop-down list if no `[itemsMaxHeight]` is specified | ||||||||||
*/ | ||||||||||
const itemsInContainer = 10; // TODO: make private readonly | ||||||||||
|
||||||||||
/** @hidden @internal */ | ||||||||||
const ItemHeights = { | ||||||||||
"3": 40, | ||||||||||
"2": 32, | ||||||||||
"1": 28 | ||||||||||
}; | ||||||||||
|
||||||||||
/** @hidden @internal */ | ||||||||||
export const enum DataTypes { | ||||||||||
|
@@ -234,8 +221,8 @@ export abstract class IgxComboBaseDirective implements IgxComboBase, AfterViewCh | |||||||||
*/ | ||||||||||
@Input() | ||||||||||
public get itemsMaxHeight(): number { | ||||||||||
if (this._itemsMaxHeight === null || this._itemsMaxHeight === undefined) { | ||||||||||
return this.itemHeight * itemsInContainer; | ||||||||||
if (this.itemHeight && !this._itemsMaxHeight) { | ||||||||||
return this.itemHeight * this.itemsInCointaner; | ||||||||||
} | ||||||||||
return this._itemsMaxHeight; | ||||||||||
} | ||||||||||
|
@@ -246,15 +233,9 @@ export abstract class IgxComboBaseDirective implements IgxComboBase, AfterViewCh | |||||||||
|
||||||||||
/** @hidden */ | ||||||||||
public get itemsMaxHeightInRem() { | ||||||||||
return rem(this.itemsMaxHeight); | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* @hidden | ||||||||||
* @internal | ||||||||||
*/ | ||||||||||
public get comboSize(): Size { | ||||||||||
return this.computedStyles?.getPropertyValue('--ig-size') || Size.Large; | ||||||||||
if (this.itemsMaxHeight) { | ||||||||||
return rem(this.itemsMaxHeight); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
|
@@ -272,9 +253,6 @@ export abstract class IgxComboBaseDirective implements IgxComboBase, AfterViewCh | |||||||||
*/ | ||||||||||
@Input() | ||||||||||
public get itemHeight(): number { | ||||||||||
if (this._itemHeight === null || this._itemHeight === undefined) { | ||||||||||
return ItemHeights[this.comboSize]; | ||||||||||
} | ||||||||||
return this._itemHeight; | ||||||||||
} | ||||||||||
|
||||||||||
|
@@ -943,6 +921,9 @@ export abstract class IgxComboBaseDirective implements IgxComboBase, AfterViewCh | |||||||||
public set filteringOptions(value: IComboFilteringOptions) { | ||||||||||
this._filteringOptions = value; | ||||||||||
} | ||||||||||
|
||||||||||
protected containerSize = undefined; | ||||||||||
protected itemSize = undefined; | ||||||||||
protected _data = []; | ||||||||||
protected _value = []; | ||||||||||
protected _displayValue = ''; | ||||||||||
|
@@ -963,12 +944,13 @@ export abstract class IgxComboBaseDirective implements IgxComboBase, AfterViewCh | |||||||||
private _id: string = `igx-combo-${NEXT_ID++}`; | ||||||||||
private _type = null; | ||||||||||
private _dataType = ''; | ||||||||||
private _itemHeight = null; | ||||||||||
private _itemHeight = undefined; | ||||||||||
private _itemsMaxHeight = null; | ||||||||||
private _overlaySettings: OverlaySettings; | ||||||||||
private _groupSortingDirection: SortingDirection = SortingDirection.Asc; | ||||||||||
private _filteringOptions: IComboFilteringOptions; | ||||||||||
private _defaultFilteringOptions: IComboFilteringOptions = { caseSensitive: false }; | ||||||||||
private itemsInCointaner = 10; | ||||||||||
|
||||||||||
public abstract dropdown: IgxComboDropDownComponent; | ||||||||||
public abstract selectionChanging: EventEmitter<any>; | ||||||||||
|
@@ -1029,6 +1011,16 @@ export abstract class IgxComboBaseDirective implements IgxComboBase, AfterViewCh | |||||||||
const eventArgs: IForOfState = Object.assign({}, e, { owner: this }); | ||||||||||
this.dataPreLoad.emit(eventArgs); | ||||||||||
}); | ||||||||||
this.dropdown?.animationStarting.subscribe((_args: ToggleViewEventArgs) => { | ||||||||||
// calculate the container size and item size based on the sizes from the DOM | ||||||||||
const dropdownContainerHeight = this.dropdownContainer.nativeElement.getBoundingClientRect().height; | ||||||||||
if (dropdownContainerHeight) { | ||||||||||
this.containerSize = parseFloat(dropdownContainerHeight); | ||||||||||
} | ||||||||||
if (this.dropdown.children?.first) { | ||||||||||
this.itemSize = this.dropdown.children.first.element.nativeElement.getBoundingClientRect().height; | ||||||||||
} | ||||||||||
}); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, so this is happening because the overlay igniteui-angular/projects/igniteui-angular/src/lib/services/overlay/overlay.ts Lines 424 to 427 in 509f5a6
As we discussed, the things Alternatively, the combo itself can patch opening and force the update sooner to be able to calculate those on opening. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, it's also quite possible we could move the |
||||||||||
} | ||||||||||
|
||||||||||
/** @hidden @internal */ | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,6 +168,14 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U | |
@Input() | ||
public igxForContainerSize: any; | ||
|
||
/** | ||
* @hidden | ||
* @internal | ||
* Initial chunk size if no container size is passed. If container size is passed then the igxForOf calculates its chunk size | ||
*/ | ||
@Input() | ||
public igxForInitialChunkSize: any; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess existing combo tests somewhat cover the use of |
||
|
||
/** | ||
* Sets the px-affixed size of the item along the axis of scrolling. | ||
* For "horizontal" orientation this value is the width of the column and for "vertical" is the height or the row. | ||
|
@@ -1207,7 +1215,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U | |
} | ||
} else { | ||
if (this.igxForOf) { | ||
chunkSize = this.igxForOf.length; | ||
chunkSize = Math.min(this.igxForInitialChunkSize || this.igxForOf.length, this.igxForOf.length); | ||
} | ||
} | ||
return chunkSize; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo ->
itemsInContainer
:)