@@ -25,10 +25,6 @@ export class SelectPositioningStrategy extends BaseFitPositionStrategy implement
25
25
this . settings = Object . assign ( { } , this . _selectDefaultSettings , settings ) ;
26
26
}
27
27
28
- // private itemElement = this.getInteractionItemElement();
29
- // private itemBoundRect = this.itemElement.getBoundingClientRect() as DOMRect;
30
-
31
-
32
28
// Global variables required for cases of !initialCall (page scroll/overlay repositionAll)
33
29
private global_yOffset = 0 ;
34
30
private global_xOffset = 0 ;
@@ -56,6 +52,8 @@ export class SelectPositioningStrategy extends BaseFitPositionStrategy implement
56
52
57
53
// Fill in the required selectFit object properties.
58
54
this . calculateVariables ( selectFit ) ;
55
+ // Calculate input and selected item elements style related variables
56
+ selectFit . styles = this . calculateStyles ( selectFit ) ;
59
57
selectFit . viewPortRect = Util . getViewportRect ( document ) ;
60
58
61
59
// Calculate how much to offset the overlay container.
@@ -75,14 +73,14 @@ export class SelectPositioningStrategy extends BaseFitPositionStrategy implement
75
73
76
74
public itemIsInvisible ( selectFit : SelectFit ) {
77
75
// selected item is completely invisible
78
- return Math . round ( selectFit . itemElement . getBoundingClientRect ( ) . top * 100 ) / 100 >=
76
+ return Math . round ( selectFit . itemRect . top * 100 ) / 100 >=
79
77
Math . round ( selectFit . dropDownList . getBoundingClientRect ( ) . bottom * 100 ) / 100 ||
80
- Math . round ( selectFit . itemElement . getBoundingClientRect ( ) . bottom * 100 ) / 100 <=
78
+ Math . round ( selectFit . itemRect . bottom * 100 ) / 100 <=
81
79
Math . round ( selectFit . dropDownList . getBoundingClientRect ( ) . top * 100 ) / 100 ||
82
80
// selected item is partially invisible at ddl bottom
83
- Math . round ( selectFit . itemElement . getBoundingClientRect ( ) . top * 100 ) / 100 <=
81
+ Math . round ( selectFit . itemRect . top * 100 ) / 100 <=
84
82
( selectFit . dropDownList . getBoundingClientRect ( ) . bottom * 100 ) / 100 &&
85
- Math . round ( selectFit . itemElement . getBoundingClientRect ( ) . bottom * 100 ) / 100 >=
83
+ Math . round ( selectFit . itemRect . bottom * 100 ) / 100 >=
86
84
( selectFit . dropDownList . getBoundingClientRect ( ) . bottom * 100 ) / 100 ;
87
85
}
88
86
@@ -111,7 +109,7 @@ export class SelectPositioningStrategy extends BaseFitPositionStrategy implement
111
109
return 0 ;
112
110
}
113
111
114
- const elementRect = selectFit . itemElement . getBoundingClientRect ( ) ;
112
+ const elementRect = selectFit . itemRect ;
115
113
const parentRect = selectFit . dropDownList . getBoundingClientRect ( ) ;
116
114
const scrollPosition = elementRect . bottom - parentRect . bottom ;
117
115
return Math . floor ( scrollPosition ) ;
@@ -126,8 +124,7 @@ export class SelectPositioningStrategy extends BaseFitPositionStrategy implement
126
124
// Position the items outer container Below or Above the input.
127
125
fitInViewport ( contentElement : HTMLElement , selectFit : SelectFit ) {
128
126
// Position Select component's container below target/input as preferred positioning over above target/input
129
- if ( this . canFitBelowInput ( selectFit ) && this . canFitAboveInput ( selectFit ) ||
130
- ! this . canFitAboveInput ( selectFit ) ) {
127
+ if ( this . canFitBelowInput ( selectFit ) || ! this . canFitAboveInput ( selectFit ) ) {
131
128
// Calculate container starting point;
132
129
// TODO: modify the yOffset instead & use one call to super.setStyle
133
130
selectFit . top = selectFit . targetRect . top - selectFit . styles . itemTextToInputTextDiff ;
@@ -165,39 +162,38 @@ export class SelectPositioningStrategy extends BaseFitPositionStrategy implement
165
162
}
166
163
167
164
private calculateVariables ( selectFit : SelectFit ) {
168
- const itemHeight = this . getInteractionItemElement ( ) . getBoundingClientRect ( ) . height ;
169
- selectFit . styles = { } ;
165
+ selectFit . itemRect = this . getInteractionItemElement ( ) . getBoundingClientRect ( ) ;
170
166
selectFit . itemElement = this . getInteractionItemElement ( ) ;
171
- selectFit . itemHeight = itemHeight ;
172
167
selectFit . dropDownList = this . select . scrollContainer ;
173
168
selectFit . inputElement = this . select . getEditElement ( ) ;
174
- // Calculate input and selected item elements style related variables
175
- this . calculateStyles ( selectFit ) ;
176
169
}
177
170
178
- public calculateStyles ( selectFit : SelectFit ) {
171
+ public calculateStyles ( selectFit : SelectFit ) : SelectStyles {
172
+ const styles : SelectStyles = { } ;
179
173
const inputFontSize = window . getComputedStyle ( selectFit . inputElement ) . fontSize ;
180
174
const numericInputFontSize = parseFloat ( inputFontSize ) ;
181
175
const itemFontSize = window . getComputedStyle ( selectFit . itemElement ) . fontSize ;
182
176
const numericItemFontSize = parseFloat ( itemFontSize ) ;
183
177
const inputTextToInputTop = ( selectFit . targetRect . bottom - selectFit . targetRect . top - numericInputFontSize ) / 2 ;
184
- const itemTextToItemTop = ( selectFit . itemHeight - numericItemFontSize ) / 2 ;
178
+ const itemTextToItemTop = ( selectFit . itemRect . height - numericItemFontSize ) / 2 ;
185
179
// Adjust for input top padding
186
180
const negateInputPaddings = (
187
181
parseFloat ( window . getComputedStyle ( selectFit . inputElement ) . paddingTop ) -
188
182
parseFloat ( window . getComputedStyle ( selectFit . inputElement ) . paddingBottom )
189
183
) / 2 ;
190
- selectFit . styles . itemTextToInputTextDiff = Math . ceil ( itemTextToItemTop - inputTextToInputTop + negateInputPaddings ) ;
184
+ styles . itemTextToInputTextDiff = Math . ceil ( itemTextToItemTop - inputTextToInputTop + negateInputPaddings ) ;
191
185
192
186
const itemLeftPadding = window . getComputedStyle ( selectFit . itemElement ) . paddingLeft ;
193
187
const itemTextIndent = window . getComputedStyle ( selectFit . itemElement ) . textIndent ;
194
188
const numericLeftPadding = parseFloat ( itemLeftPadding ) ;
195
189
const numericTextIndent = parseFloat ( itemTextIndent ) ;
196
190
197
- selectFit . styles . itemTextPadding = numericLeftPadding ;
198
- selectFit . styles . itemTextIndent = numericTextIndent ;
191
+ styles . itemTextPadding = numericLeftPadding ;
192
+ styles . itemTextIndent = numericTextIndent ;
199
193
// 24 is the input's toggle ddl icon width
200
- selectFit . styles . contentElementNewWidth = selectFit . targetRect . width + 24 + numericLeftPadding * 2 ;
194
+ styles . contentElementNewWidth = selectFit . targetRect . width + 24 + numericLeftPadding * 2 ;
195
+
196
+ return styles ;
201
197
}
202
198
203
199
private getInteractionItemElement ( ) : HTMLElement {
@@ -217,7 +213,7 @@ export class SelectPositioningStrategy extends BaseFitPositionStrategy implement
217
213
protected calculateYoffset ( selectFit : SelectFit ) {
218
214
const contentElementTopLeftPointY = selectFit . contentElementRect . top ;
219
215
selectFit . verticalOffset =
220
- - ( selectFit . itemElement . getBoundingClientRect ( ) . top - contentElementTopLeftPointY + selectFit . styles . itemTextToInputTextDiff ) ;
216
+ - ( selectFit . itemRect . top - contentElementTopLeftPointY + selectFit . styles . itemTextToInputTextDiff ) ;
221
217
this . global_yOffset = selectFit . verticalOffset ;
222
218
}
223
219
@@ -244,7 +240,7 @@ export interface SelectFit extends ConnectedFit {
244
240
inputElement ?: HTMLElement ;
245
241
dropDownList ?: HTMLElement ;
246
242
itemElement ?: HTMLElement ;
247
- itemHeight ?: number ;
243
+ itemRect ?: ClientRect ;
248
244
styles ?: SelectStyles ;
249
245
}
250
246
0 commit comments