MDL-66312 js: Autocomplete promises were inside out
authorAndrew Nicols <andrew@nicols.co.uk>
Fri, 16 Aug 2019 03:04:11 +0000 (11:04 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Fri, 16 Aug 2019 03:40:16 +0000 (11:40 +0800)
The pending promise should nott be resolved until the changes are
complete.
Previously the resolution of the pendingPromise was triggering the other
changes.

lib/amd/build/form-autocomplete.min.js
lib/amd/build/form-autocomplete.min.js.map
lib/amd/src/form-autocomplete.js

index 549a653..1688749 100644 (file)
Binary files a/lib/amd/build/form-autocomplete.min.js and b/lib/amd/build/form-autocomplete.min.js differ
index db0aeaf..11e43c8 100644 (file)
Binary files a/lib/amd/build/form-autocomplete.min.js.map and b/lib/amd/build/form-autocomplete.min.js.map differ
index b91dd0b..43e3227 100644 (file)
@@ -718,6 +718,7 @@ function($, log, str, templates, notification, LoadingIcon) {
             window.setTimeout(function() {
                 // Get the current element with focus.
                 var focusElement = $(document.activeElement);
+                var timeoutPromise = $.Deferred();
 
                 // Only close the menu if the input hasn't regained focus and if the element still exists,
                 // and regain focus if the scrollbar is clicked.
@@ -727,18 +728,22 @@ function($, log, str, templates, notification, LoadingIcon) {
                     inputElement.focus(); // Probably the scrollbar is clicked. Regain focus.
                 } else if (!focusElement.is(inputElement) && $(document.getElementById(state.inputId)).length) {
                     if (options.tags) {
-                        pendingPromise.then(function() {
+                        timeoutPromise.then(function() {
                             return createItem(options, state, originalSelect);
                         })
                         .catch();
                     }
-                    pendingPromise.then(function() {
+                    timeoutPromise.then(function() {
                         return closeSuggestions(state);
                     })
                     .catch();
                 }
 
-                pendingPromise.resolve();
+                timeoutPromise.then(function() {
+                    return pendingPromise.resolve();
+                })
+                .catch();
+                timeoutPromise.resolve();
             }, 500);
         });
         if (options.showSuggestions) {