From c54a333a0f19a2cef249108090294660cc17ff59 Mon Sep 17 00:00:00 2001 From: kavita Date: Wed, 9 Dec 2015 17:10:05 +0530 Subject: [PATCH] Fixed #797 - Tokenizing Autocomplete suggestions with key down and keyup, scrollbar is not moving Ref. url for issue - https://github.com/loopj/jquery-tokeninput/issues/797 --- src/jquery.tokeninput.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/jquery.tokeninput.js b/src/jquery.tokeninput.js index 4b69d823..31e2dc26 100755 --- a/src/jquery.tokeninput.js +++ b/src/jquery.tokeninput.js @@ -937,6 +937,19 @@ item.addClass($(input).data("settings").classes.selectedDropdownItem); selected_dropdown_item = item.get(0); } + if (selected_dropdown_item) { + var selectedTop = $(selected_dropdown_item).offset().top, + selectedBottom = selectedTop + $(selected_dropdown_item).outerHeight(), + ddTop = $(dropdown).offset().top, + ddBottom = ddTop + $(dropdown).outerHeight(), + ddScrollTop = $(dropdown).scrollTop(); + + if (selectedBottom > ddBottom) { + $(dropdown).scrollTop(ddScrollTop + (selectedBottom - ddBottom)); + } else if (ddTop > selectedTop) { + $(dropdown).scrollTop(ddScrollTop + (selectedTop - ddTop)); + } + } } // Remove highlighting from an item in the results dropdown