MDL-52042 autocomplete: close suggestion box

Close the suggestion box when the input loses focus for more
than half a second.
This commit is contained in:
Ryan Wyllie 2015-11-09 07:31:32 +00:00
parent 1533fca4b5
commit e1db2b4112
2 changed files with 7 additions and 16 deletions

File diff suppressed because one or more lines are too long

View File

@ -37,9 +37,6 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
UP: 38
};
/** @var {Number} closeSuggestionsTimer - integer used to cancel window.setTimeout. */
var closeSuggestionsTimer = null;
/**
* Make an item in the selection list "active".
*
@ -568,15 +565,12 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
createItem(options, state, originalSelect);
}
});
inputElement.on('blur focus', function(e) {
// We may be blurring because we have clicked on the suggestion list. We
// dont want to close the selection list before the click event fires, so
// we have to delay.
if (closeSuggestionsTimer) {
window.clearTimeout(closeSuggestionsTimer);
}
closeSuggestionsTimer = window.setTimeout(function() {
if (e.type == 'blur') {
inputElement.on('blur', function() {
window.setTimeout(function() {
// Get the current element with focus.
var focusElement = $(document.activeElement);
// Only close the menu if the input hasn't regained focus.
if (focusElement.attr('id') != inputElement.attr('id')) {
if (options.tags) {
createItem(options, state, originalSelect);
}
@ -589,9 +583,6 @@ define(['jquery', 'core/log', 'core/str', 'core/templates', 'core/notification']
arrowElement.on('click', function() {
// Prevent the close timer, or we will open, then close the suggestions.
inputElement.focus();
if (closeSuggestionsTimer) {
window.clearTimeout(closeSuggestionsTimer);
}
// Show the suggestions list.
updateSuggestions(options, state, inputElement.val(), originalSelect);
});