Keep the focused item visible when navigating the search-to-add results with the arrow keys

This commit is contained in:
Quincy Morgan
2019-03-04 10:51:23 -05:00
parent 7bf73111c4
commit fa2e718edf

View File

@@ -159,7 +159,17 @@ export function uiSearchAdd(context) {
function focusListItem(selection) {
if (!selection.empty()) {
selection.classed('focused', true);
//selection.nodes()[0].scrollIntoView();
var node = selection.nodes()[0];
var popoverNode = popover.node();
var nodeRect = node.getBoundingClientRect();
// scroll to keep the focused item visible
if (node.offsetTop < popoverNode.scrollTop) {
popoverNode.scrollTop = node.offsetTop;
} else if (node.offsetTop + node.offsetHeight > popoverNode.scrollTop + popoverNode.offsetHeight) {
popoverNode.scrollTop = node.offsetTop + node.offsetHeight - popoverNode.offsetHeight;
}
}
}