Skip to content

Commit

Permalink
Merge pull request #551 from scireum/fwe/IEScrollBugFix
Browse files Browse the repository at this point in the history
 Replaces the method used to scroll the selected autocomplete row in view
  • Loading branch information
andyHa authored Jan 21, 2019
2 parents 1c82544 + 42f8a80 commit 7d784c1
Showing 1 changed file with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,14 @@
state: undefined,

config: undefined,

/**
* Initializes the completions element.
*
* Keys of the config object are:
* - id: the id of the autocomplete wrapper div
* - width: the width for the element if it should differ from the anchor
* - height: the max-height of the element
*/
init: function (config) {
this.config = config;
Expand Down Expand Up @@ -290,13 +293,40 @@
hoverRow: function ($row) {
completions.selectedRow = $row;
$row.addClass("autocomplete-selected-element");
$row.get(0).scrollIntoView({block: "nearest", inline: "nearest"})
completions.scrollRowIntoView($row.get(0));

events.onHoverRow.forEach(function (handler) {
handler($row);
});
},

/**
* If the given row is outside the view, scroll it into view.
*
* Only used if the completions.height config is set, or else the element will just be as high as it
* needs to be to display all completions without scrolling.
*
* @@param row the row to be scrolled into the view
*/
scrollRowIntoView: function (row) {
var container = row.parentNode;

if (container.scrollTop > row.offsetTop) {
// row is above the position the container scrolled to
// -> we should scroll up so the row is on the top of the viewable space
container.scrollTop = row.offsetTop;
return;
}

var containerBottom = container.scrollTop + container.offsetHeight;
var rowBottom = row.offsetTop + row.offsetHeight;
if (containerBottom < rowBottom) {
// row is below the bottom position the container scrolled to
// -> we should scroll down so the row is on the bottom of the viewable space
container.scrollTop = rowBottom - container.offsetHeight;
}
},

unHoverRow: function ($row) {
if ($row) {
$row.removeClass("autocomplete-selected-element");
Expand Down

0 comments on commit 7d784c1

Please sign in to comment.