MDL-68167 lib: autocomplete focos should not be removed on blur
[moodle.git] / lib / amd / src / form-autocomplete.js
index 8788e94..83dd16b 100644 (file)
@@ -812,17 +812,14 @@ function($, log, str, templates, notification, LoadingIcon, Aria) {
             // Remove it from the selection.
             pendingPromise.resolve(deselectItem(options, state, $(e.currentTarget), originalSelect));
         });
-        // Remove the highlight of items when user tabs out the tag list.
-        selectionElement.on('blur', function(e) {
-            e.preventDefault();
-            $(this).children().attr('data-active-selection', false).attr('id', '');
-        });
-        // When tag list is focused, highlight the first item.
-        selectionElement.on('focus', function(e) {
-            e.preventDefault();
-            var element = $(this).children('[data-active-selection=true]');
-            if (element && element.length === 0) {
-                activateNextSelection(state);
+        // When listbox is focused, focus on the first option if there is no focused option.
+        selectionElement.on('focus', function() {
+            // Find the list of selections.
+            var selectionsElement = $(document.getElementById(state.selectionId));
+            // Find the active one.
+            var element = selectionsElement.children('[data-active-selection=true]');
+            if (!element.length) {
+                return activateSelection(0, state);
             }
         });
         // Keyboard navigation for the selection list.