@@ -25,10 +25,6 @@ export class SelectPositioningStrategy extends BaseFitPositionStrategy implement
2525 this . settings = Object . assign ( { } , this . _selectDefaultSettings , settings ) ;
2626 }
2727
28- // private itemElement = this.getInteractionItemElement();
29- // private itemBoundRect = this.itemElement.getBoundingClientRect() as DOMRect;
30-
31-
3228 // Global variables required for cases of !initialCall (page scroll/overlay repositionAll)
3329 private global_yOffset = 0 ;
3430 private global_xOffset = 0 ;
@@ -56,6 +52,8 @@ export class SelectPositioningStrategy extends BaseFitPositionStrategy implement
5652
5753 // Fill in the required selectFit object properties.
5854 this . calculateVariables ( selectFit ) ;
55+ // Calculate input and selected item elements style related variables
56+ selectFit . styles = this . calculateStyles ( selectFit ) ;
5957 selectFit . viewPortRect = Util . getViewportRect ( document ) ;
6058
6159 // Calculate how much to offset the overlay container.
@@ -75,14 +73,14 @@ export class SelectPositioningStrategy extends BaseFitPositionStrategy implement
7573
7674 public itemIsInvisible ( selectFit : SelectFit ) {
7775 // selected item is completely invisible
78- return Math . round ( selectFit . itemElement . getBoundingClientRect ( ) . top * 100 ) / 100 >=
76+ return Math . round ( selectFit . itemRect . top * 100 ) / 100 >=
7977 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 <=
8179 Math . round ( selectFit . dropDownList . getBoundingClientRect ( ) . top * 100 ) / 100 ||
8280 // 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 <=
8482 ( selectFit . dropDownList . getBoundingClientRect ( ) . bottom * 100 ) / 100 &&
85- Math . round ( selectFit . itemElement . getBoundingClientRect ( ) . bottom * 100 ) / 100 >=
83+ Math . round ( selectFit . itemRect . bottom * 100 ) / 100 >=
8684 ( selectFit . dropDownList . getBoundingClientRect ( ) . bottom * 100 ) / 100 ;
8785 }
8886
@@ -111,7 +109,7 @@ export class SelectPositioningStrategy extends BaseFitPositionStrategy implement
111109 return 0 ;
112110 }
113111
114- const elementRect = selectFit . itemElement . getBoundingClientRect ( ) ;
112+ const elementRect = selectFit . itemRect ;
115113 const parentRect = selectFit . dropDownList . getBoundingClientRect ( ) ;
116114 const scrollPosition = elementRect . bottom - parentRect . bottom ;
117115 return Math . floor ( scrollPosition ) ;
@@ -126,8 +124,7 @@ export class SelectPositioningStrategy extends BaseFitPositionStrategy implement
126124 // Position the items outer container Below or Above the input.
127125 fitInViewport ( contentElement : HTMLElement , selectFit : SelectFit ) {
128126 // 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 ) ) {
131128 // Calculate container starting point;
132129 // TODO: modify the yOffset instead & use one call to super.setStyle
133130 selectFit . top = selectFit . targetRect . top - selectFit . styles . itemTextToInputTextDiff ;
@@ -165,39 +162,38 @@ export class SelectPositioningStrategy extends BaseFitPositionStrategy implement
165162 }
166163
167164 private calculateVariables ( selectFit : SelectFit ) {
168- const itemHeight = this . getInteractionItemElement ( ) . getBoundingClientRect ( ) . height ;
169- selectFit . styles = { } ;
165+ selectFit . itemRect = this . getInteractionItemElement ( ) . getBoundingClientRect ( ) ;
170166 selectFit . itemElement = this . getInteractionItemElement ( ) ;
171- selectFit . itemHeight = itemHeight ;
172167 selectFit . dropDownList = this . select . scrollContainer ;
173168 selectFit . inputElement = this . select . getEditElement ( ) ;
174- // Calculate input and selected item elements style related variables
175- this . calculateStyles ( selectFit ) ;
176169 }
177170
178- public calculateStyles ( selectFit : SelectFit ) {
171+ public calculateStyles ( selectFit : SelectFit ) : SelectStyles {
172+ const styles : SelectStyles = { } ;
179173 const inputFontSize = window . getComputedStyle ( selectFit . inputElement ) . fontSize ;
180174 const numericInputFontSize = parseFloat ( inputFontSize ) ;
181175 const itemFontSize = window . getComputedStyle ( selectFit . itemElement ) . fontSize ;
182176 const numericItemFontSize = parseFloat ( itemFontSize ) ;
183177 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 ;
185179 // Adjust for input top padding
186180 const negateInputPaddings = (
187181 parseFloat ( window . getComputedStyle ( selectFit . inputElement ) . paddingTop ) -
188182 parseFloat ( window . getComputedStyle ( selectFit . inputElement ) . paddingBottom )
189183 ) / 2 ;
190- selectFit . styles . itemTextToInputTextDiff = Math . ceil ( itemTextToItemTop - inputTextToInputTop + negateInputPaddings ) ;
184+ styles . itemTextToInputTextDiff = Math . ceil ( itemTextToItemTop - inputTextToInputTop + negateInputPaddings ) ;
191185
192186 const itemLeftPadding = window . getComputedStyle ( selectFit . itemElement ) . paddingLeft ;
193187 const itemTextIndent = window . getComputedStyle ( selectFit . itemElement ) . textIndent ;
194188 const numericLeftPadding = parseFloat ( itemLeftPadding ) ;
195189 const numericTextIndent = parseFloat ( itemTextIndent ) ;
196190
197- selectFit . styles . itemTextPadding = numericLeftPadding ;
198- selectFit . styles . itemTextIndent = numericTextIndent ;
191+ styles . itemTextPadding = numericLeftPadding ;
192+ styles . itemTextIndent = numericTextIndent ;
199193 // 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 ;
201197 }
202198
203199 private getInteractionItemElement ( ) : HTMLElement {
@@ -217,7 +213,7 @@ export class SelectPositioningStrategy extends BaseFitPositionStrategy implement
217213 protected calculateYoffset ( selectFit : SelectFit ) {
218214 const contentElementTopLeftPointY = selectFit . contentElementRect . top ;
219215 selectFit . verticalOffset =
220- - ( selectFit . itemElement . getBoundingClientRect ( ) . top - contentElementTopLeftPointY + selectFit . styles . itemTextToInputTextDiff ) ;
216+ - ( selectFit . itemRect . top - contentElementTopLeftPointY + selectFit . styles . itemTextToInputTextDiff ) ;
221217 this . global_yOffset = selectFit . verticalOffset ;
222218 }
223219
@@ -244,7 +240,7 @@ export interface SelectFit extends ConnectedFit {
244240 inputElement ?: HTMLElement ;
245241 dropDownList ?: HTMLElement ;
246242 itemElement ?: HTMLElement ;
247- itemHeight ?: number ;
243+ itemRect ?: ClientRect ;
248244 styles ?: SelectStyles ;
249245}
250246
0 commit comments