@@ -37,25 +37,25 @@ export class SelectPositioningStrategy extends ConnectedPositioningStrategy impl
37
37
private deltaX : number ;
38
38
private itemTextPadding : number ;
39
39
private itemTextIndent : number ;
40
- private inputBorderTop : number ;
41
40
private listContainerBoundRect : DOMRect ;
41
+ private itemTextToInputTextDiff : number ;
42
42
43
43
private positionAndScrollBottom ( contentElement : HTMLElement , outBoundsAmount : number ) {
44
44
contentElement . style . top = `${ this . viewPort . bottom - this . listContainerBoundRect . height - this . defaultWindowToListOffset } px` ;
45
- contentElement . firstElementChild . scrollTop -= outBoundsAmount - ( this . inputBorderTop - this . defaultWindowToListOffset ) ;
45
+ contentElement . firstElementChild . scrollTop -= outBoundsAmount - ( this . defaultWindowToListOffset ) ;
46
46
this . deltaY = this . viewPort . bottom - this . listContainerBoundRect . height -
47
47
this . defaultWindowToListOffset - ( this . select . input . nativeElement . getBoundingClientRect ( ) as DOMRect ) . top ;
48
48
}
49
49
50
50
private positionNoScroll ( contentElement : HTMLElement , CURRENT_POSITION_Y : number ) {
51
- contentElement . style . top = `${ CURRENT_POSITION_Y - this . inputBorderTop } px` ;
52
- this . deltaY = CURRENT_POSITION_Y - this . inputBorderTop -
53
- ( this . select . input . nativeElement . getBoundingClientRect ( ) as DOMRect ) . top ;
51
+ contentElement . style . top = `${ CURRENT_POSITION_Y - this . itemTextToInputTextDiff } px` ;
52
+ this . deltaY = CURRENT_POSITION_Y -
53
+ ( this . select . input . nativeElement . getBoundingClientRect ( ) as DOMRect ) . top - this . itemTextToInputTextDiff ;
54
54
}
55
55
56
56
private positionAndScrollTop ( contentElement : HTMLElement , outBoundsAmount : number ) {
57
57
contentElement . style . top = `${ this . viewPort . top + this . defaultWindowToListOffset } px` ;
58
- contentElement . firstElementChild . scrollTop += outBoundsAmount + this . inputBorderTop + this . defaultWindowToListOffset ;
58
+ contentElement . firstElementChild . scrollTop += outBoundsAmount + this . itemTextToInputTextDiff + this . defaultWindowToListOffset ;
59
59
this . deltaY = this . viewPort . top + this . defaultWindowToListOffset -
60
60
( this . select . input . nativeElement . getBoundingClientRect ( ) as DOMRect ) . top ;
61
61
}
@@ -140,6 +140,14 @@ export class SelectPositioningStrategy extends ConnectedPositioningStrategy impl
140
140
const itemTopListOffset = itemBoundRect . top - this . listContainerBoundRect . top ;
141
141
const itemHeight = itemBoundRect . height ;
142
142
143
+ const inputFontSize = window . getComputedStyle ( inputElement ) . fontSize ;
144
+ const numericInputFontSize = parseInt ( inputFontSize . slice ( 0 , inputFontSize . indexOf ( 'p' ) ) , 10 ) || 0 ;
145
+ const itemFontSize = window . getComputedStyle ( itemElement ) . fontSize ;
146
+ const numericItemFontSize = parseInt ( itemFontSize . slice ( 0 , itemFontSize . indexOf ( 'p' ) ) , 10 ) || 0 ;
147
+ const inputTextToInputTop = ( inputHeight - numericInputFontSize ) / 2 ;
148
+ const itemTextToItemTop = ( itemHeight - numericItemFontSize ) / 2 ;
149
+ this . itemTextToInputTextDiff = itemTextToItemTop - inputTextToInputTop ;
150
+
143
151
let CURRENT_POSITION_Y = START . Y - itemTopListOffset ;
144
152
const CURRENT_BOTTOM_Y = CURRENT_POSITION_Y + this . listContainerBoundRect . height ;
145
153
@@ -155,17 +163,15 @@ export class SelectPositioningStrategy extends ConnectedPositioningStrategy impl
155
163
CURRENT_POSITION_Y += START . Y ;
156
164
}
157
165
}
158
- const inputBorderTop = window . getComputedStyle ( inputElement ) . borderTopWidth ;
159
- this . inputBorderTop = parseInt ( inputBorderTop . slice ( 0 , inputBorderTop . indexOf ( 'p' ) ) , 10 ) || 0 ;
160
166
const itemLeftPadding = window . getComputedStyle ( itemElement ) . paddingLeft ;
161
167
const itemTextIndent = window . getComputedStyle ( itemElement ) . textIndent ;
162
- const numericPadding = parseInt ( itemLeftPadding . slice ( 0 , itemLeftPadding . indexOf ( 'p' ) ) , 10 ) || 0 ;
168
+ const numericLeftPadding = parseInt ( itemLeftPadding . slice ( 0 , itemLeftPadding . indexOf ( 'p' ) ) , 10 ) || 0 ;
163
169
const numericTextIndent = parseInt ( itemTextIndent . slice ( 0 , itemTextIndent . indexOf ( 'r' ) ) , 10 ) || 0 ;
164
- this . itemTextPadding = numericPadding ;
170
+ this . itemTextPadding = numericLeftPadding ;
165
171
this . itemTextIndent = numericTextIndent ;
166
- contentElement . style . left += `${ START . X - numericPadding - numericTextIndent } px` ;
172
+ contentElement . style . left += `${ START . X - numericLeftPadding - numericTextIndent } px` ;
167
173
contentElement . style . width = inputRect . width + 24 + 32 + 'px' ;
168
- this . deltaX = START . X - numericPadding - numericTextIndent ;
174
+ this . deltaX = START . X - numericLeftPadding - numericTextIndent ;
169
175
const currentScroll = this . getItemsOutOfView ( contentElement , itemHeight ) [ 'currentScroll' ] ;
170
176
const remainingScroll = this . getItemsOutOfView ( contentElement , itemHeight ) [ 'remainingScroll' ] ;
171
177
0 commit comments