File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -110,8 +110,8 @@ class Autocomplete {
110110 }
111111
112112 this . updateList ( ) ;
113- this . updatePosition ( ) ;
114113 this . container . style . display = 'block' ;
114+ this . updatePosition ( ) ;
115115 }
116116
117117 async updateList ( ) {
@@ -273,11 +273,21 @@ class Autocomplete {
273273 const rect = this . input . getBoundingClientRect ( ) ;
274274 this . container . style . minWidth = Pixels ( this . input . offsetWidth ) ;
275275
276+ // Calculate Y offset if menu does not fit to the bottom of the screen -> show it at the top of the input field
277+ const menuRect = this . container . getBoundingClientRect ( ) ;
278+ const totalHeight = menuRect . height + rect . height ;
279+ const menuOffset = ( totalHeight + rect . y ) > window . self . visualViewport . height ? totalHeight : 0 ;
280+ if ( menuOffset > 0 ) {
281+ this . container . classList . add ( 'kpxcAutocomplete-container-on-top' ) ;
282+ } else {
283+ this . container . classList . remove ( 'kpxcAutocomplete-container-on-top' ) ;
284+ }
285+
276286 if ( kpxcUI . bodyStyle . position . toLowerCase ( ) === 'relative' ) {
277- this . container . style . top = Pixels ( rect . top - kpxcUI . bodyRect . top + document . scrollingElement . scrollTop + this . input . offsetHeight ) ;
287+ this . container . style . top = Pixels ( rect . top - kpxcUI . bodyRect . top + document . scrollingElement . scrollTop + this . input . offsetHeight - menuOffset ) ;
278288 this . container . style . left = Pixels ( rect . left - kpxcUI . bodyRect . left + document . scrollingElement . scrollLeft ) ;
279289 } else {
280- this . container . style . top = Pixels ( rect . top + document . scrollingElement . scrollTop + this . input . offsetHeight ) ;
290+ this . container . style . top = Pixels ( rect . top + document . scrollingElement . scrollTop + this . input . offsetHeight - menuOffset ) ;
281291 this . container . style . left = Pixels ( rect . left + document . scrollingElement . scrollLeft ) ;
282292 }
283293 }
Original file line number Diff line number Diff line change 88 overflow : hidden; /* this fixes an issue with the border radius not showing up clearly */
99}
1010
11+ .kpxcAutocomplete-container-on-top {
12+ border-bottom-right-radius : 0px ;
13+ border-bottom-left-radius : 0px ;
14+ border-top-right-radius : 4px ;
15+ border-top-left-radius : 4px ;
16+ }
17+
1118.kpxcAutocomplete-items {
1219 max-height : 250px ;
1320 overflow-y : auto;
You can’t perform that action at this time.
0 commit comments