MDL-51838 autocomplete: Scroll the suggestions list

Keep the active item "visible" when using keyboard nav on a long list of suggestions.
This commit is contained in:
Damyon Wiese 2015-10-26 12:20:33 +08:00
parent 9382ac38d6
commit 32f3de567f
2 changed files with 10 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@ -133,6 +133,15 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
element.attr('aria-selected', true).attr('id', itemId);
// Tell the input field it has a new active descendant so the item is announced.
inputElement.attr('aria-activedescendant', itemId);
// Scroll it into view.
var scrollPos = element.offset().top
- suggestionsElement.offset().top
+ suggestionsElement.scrollTop()
- (suggestionsElement.height() / 2);
suggestionsElement.animate({
scrollTop: scrollPos
}, 100);
};
/**