Skip to content

Commit a52bc85

Browse files
committed
chore(select): Address comments-4 #5911
1 parent 43cb8d3 commit a52bc85

File tree

4 files changed

+15
-42
lines changed

4 files changed

+15
-42
lines changed

projects/igniteui-angular/src/lib/select/select-positioning-strategy.ts

+11-31
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import { fadeOut, fadeIn } from '../animations/main';
44
import { IgxSelectBase } from './select.common';
55
import { isIE } from '../core/utils';
66
import { BaseFitPositionStrategy } from '../services/overlay/position/base-fit-position-strategy';
7-
import { DisplayDensity } from '../core/density';
87

98
/** @hidden @internal */
109
export class SelectPositioningStrategy extends BaseFitPositionStrategy implements IPositionStrategy {
1110

1211
private _selectDefaultSettings = {
13-
target: this.select.getEditElement().getBoundingClientRect().top, // ** Use top target here and top item for positioning bellow **
1412
horizontalDirection: HorizontalAlignment.Right,
1513
verticalDirection: VerticalAlignment.Bottom,
1614
horizontalStartPoint: HorizontalAlignment.Left,
@@ -74,14 +72,14 @@ export class SelectPositioningStrategy extends BaseFitPositionStrategy implement
7472
public itemIsInvisible(selectFit: SelectFit) {
7573
// selected item is completely invisible
7674
return Math.round(selectFit.itemRect.top * 100) / 100 >=
77-
Math.round(selectFit.dropDownList.getBoundingClientRect().bottom * 100) / 100 ||
75+
Math.round(this.select.scrollContainer.getBoundingClientRect().bottom * 100) / 100 ||
7876
Math.round(selectFit.itemRect.bottom * 100) / 100 <=
79-
Math.round(selectFit.dropDownList.getBoundingClientRect().top * 100) / 100 ||
77+
Math.round(this.select.scrollContainer.getBoundingClientRect().top * 100) / 100 ||
8078
// selected item is partially invisible at ddl bottom
8179
Math.round(selectFit.itemRect.top * 100) / 100 <=
82-
(selectFit.dropDownList.getBoundingClientRect().bottom * 100) / 100 &&
80+
(this.select.scrollContainer.getBoundingClientRect().bottom * 100) / 100 &&
8381
Math.round(selectFit.itemRect.bottom * 100) / 100 >=
84-
(selectFit.dropDownList.getBoundingClientRect().bottom * 100) / 100;
82+
(this.select.scrollContainer.getBoundingClientRect().bottom * 100) / 100;
8583
}
8684

8785
private manageScrollToItem(selectFit: SelectFit) {
@@ -96,10 +94,10 @@ export class SelectPositioningStrategy extends BaseFitPositionStrategy implement
9694
const itemPosition = this.calculateScrollPosition(selectFit);
9795
if (isIE()) {
9896
setTimeout(() => {
99-
selectFit.dropDownList.scrollTop = (itemPosition);
97+
this.select.scrollContainer.scrollTop = (itemPosition);
10098
}, 1);
10199
} else {
102-
selectFit.dropDownList.scrollTop = (itemPosition);
100+
this.select.scrollContainer.scrollTop = (itemPosition);
103101
}
104102
return itemPosition;
105103
}
@@ -110,7 +108,7 @@ export class SelectPositioningStrategy extends BaseFitPositionStrategy implement
110108
}
111109

112110
const elementRect = selectFit.itemRect;
113-
const parentRect = selectFit.dropDownList.getBoundingClientRect();
111+
const parentRect = this.select.scrollContainer.getBoundingClientRect();
114112
const scrollPosition = elementRect.bottom - parentRect.bottom;
115113
return Math.floor(scrollPosition);
116114
}
@@ -164,22 +162,20 @@ export class SelectPositioningStrategy extends BaseFitPositionStrategy implement
164162
private calculateVariables(selectFit: SelectFit) {
165163
selectFit.itemRect = this.getInteractionItemElement().getBoundingClientRect();
166164
selectFit.itemElement = this.getInteractionItemElement();
167-
selectFit.dropDownList = this.select.scrollContainer;
168-
selectFit.inputElement = this.select.getEditElement();
169-
}
165+
}
170166

171167
public calculateStyles(selectFit: SelectFit): SelectStyles {
172168
const styles: SelectStyles = {};
173-
const inputFontSize = window.getComputedStyle(selectFit.inputElement).fontSize;
169+
const inputFontSize = window.getComputedStyle(this.settings.target as Element).fontSize;
174170
const numericInputFontSize = parseFloat(inputFontSize);
175171
const itemFontSize = window.getComputedStyle(selectFit.itemElement).fontSize;
176172
const numericItemFontSize = parseFloat(itemFontSize);
177173
const inputTextToInputTop = (selectFit.targetRect.bottom - selectFit.targetRect.top - numericInputFontSize) / 2;
178174
const itemTextToItemTop = (selectFit.itemRect.height - numericItemFontSize) / 2;
179175
// Adjust for input top padding
180176
const negateInputPaddings = (
181-
parseFloat(window.getComputedStyle(selectFit.inputElement).paddingTop) -
182-
parseFloat(window.getComputedStyle(selectFit.inputElement).paddingBottom)
177+
parseFloat(window.getComputedStyle(this.settings.target as Element).paddingTop) -
178+
parseFloat(window.getComputedStyle(this.settings.target as Element).paddingBottom)
183179
) / 2;
184180
styles.itemTextToInputTextDiff = Math.ceil(itemTextToItemTop - inputTextToInputTop + negateInputPaddings);
185181

@@ -224,21 +220,6 @@ export class SelectPositioningStrategy extends BaseFitPositionStrategy implement
224220
}
225221

226222
export interface SelectFit extends ConnectedFit {
227-
contentElementRect?: ClientRect;
228-
targetRect?: ClientRect;
229-
viewPortRect?: ClientRect;
230-
fitHorizontal?: boolean;
231-
fitVertical?: boolean;
232-
left?: number;
233-
right?: number;
234-
top?: number;
235-
bottom?: number;
236-
horizontalOffset?: number;
237-
verticalOffset?: number;
238-
239-
// New properties
240-
inputElement?: HTMLElement;
241-
dropDownList?: HTMLElement;
242223
itemElement?: HTMLElement;
243224
itemRect?: ClientRect;
244225
styles?: SelectStyles;
@@ -249,7 +230,6 @@ export interface SelectStyles {
249230
itemTextIndent?: number;
250231
itemTextToInputTextDiff?: number;
251232
contentElementNewWidth?: number;
252-
displayDensity?: DisplayDensity | string;
253233
numericLeftPadding?: number;
254234
}
255235

projects/igniteui-angular/src/lib/select/select.common.ts

-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@ export interface IgxSelectBase extends IgxDropDownBaseDirective {
1111
toggle(overlaySettings?: OverlaySettings);
1212
calculateScrollPosition(item: IgxDropDownItemBaseDirective): number;
1313
getFirstItemElement(): HTMLElement;
14-
getListItemsContainer(): HTMLElement;
1514
getEditElement(): HTMLElement; // returns input HTMLElement
1615
}

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

-5
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,6 @@ export class IgxSelectComponent extends IgxDropDownComponent implements IgxSelec
312312
return this.children.first.element.nativeElement;
313313
}
314314

315-
/** @hidden @internal */
316-
public getListItemsContainer(): HTMLElement {
317-
return this.getFirstItemElement().parentElement;
318-
}
319-
320315
/**
321316
* Opens the select
322317
*

projects/igniteui-angular/src/lib/services/overlay/position/base-fit-position-strategy.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ export abstract class BaseFitPositionStrategy extends ConnectedPositioningStrate
77

88
/** @inheritdoc */
99
position(contentElement: HTMLElement, size: Size, document?: Document, initialCall?: boolean): void {
10-
const targetRect = super.calculateElementRectangles(contentElement).targetRect;
11-
const contentElementRect = contentElement.getBoundingClientRect();
10+
const rects = super.calculateElementRectangles(contentElement);
1211
const connectedFit: ConnectedFit = {};
1312
if (initialCall) {
14-
connectedFit.targetRect = targetRect;
15-
connectedFit.contentElementRect = contentElementRect;
13+
connectedFit.targetRect = rects.targetRect;
14+
connectedFit.contentElementRect = rects.elementRect;
1615
this._initialSettings = this._initialSettings || Object.assign({}, this.settings);
1716
this.settings = Object.assign({}, this._initialSettings);
1817
connectedFit.viewPortRect = Util.getViewportRect(document);
@@ -21,7 +20,7 @@ export abstract class BaseFitPositionStrategy extends ConnectedPositioningStrate
2120
this.fitInViewport(contentElement, connectedFit);
2221
}
2322
}
24-
this.setStyle(contentElement, targetRect, contentElementRect, connectedFit);
23+
this.setStyle(contentElement, rects.targetRect, rects.elementRect, connectedFit);
2524
}
2625

2726
/**

0 commit comments

Comments
 (0)