MDL-70075 core: jQuery.attr() does not accept a bool value
authorAndrew Nicols <andrew@nicols.co.uk>
Mon, 2 Nov 2020 07:42:13 +0000 (15:42 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Wed, 4 Nov 2020 03:27:55 +0000 (11:27 +0800)
The documented values that jQuery.attr() accepts are String, Number, or
null. For some reason, when we pass a Boolean value, the subsequent
click handler does not work in some situations.

Changing this to take a Number, and unsetting it when empty, resolves
this issue.

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

index ce28280..fa95f55 100644 (file)
Binary files a/lib/amd/build/form-autocomplete.min.js and b/lib/amd/build/form-autocomplete.min.js differ
index 09d885c..db17485 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 83dd16b..72a6e57 100644 (file)
@@ -69,9 +69,11 @@ function($, log, str, templates, notification, LoadingIcon, Aria) {
         var itemId = state.selectionId + '-' + index;
 
         // Deselect all the selections.
-        selectionElement.children().attr('data-active-selection', false).attr('id', '');
+        selectionElement.children().attr('data-active-selection', null).attr('id', '');
+
         // Select only this suggestion and assign it the id.
         element.attr('data-active-selection', true).attr('id', itemId);
+
         // Tell the input field it has a new active descendant so the item is announced.
         selectionElement.attr('aria-activedescendant', itemId);
 
@@ -263,7 +265,7 @@ function($, log, str, templates, notification, LoadingIcon, Aria) {
         // Find the list of selections.
         var selectionsElement = $(document.getElementById(state.selectionId));
         // Find the active one.
-        var element = selectionsElement.children('[data-active-selection=true]');
+        var element = selectionsElement.children('[data-active-selection]');
         if (!element) {
             return activateSelection(0, state);
         }
@@ -286,7 +288,7 @@ function($, log, str, templates, notification, LoadingIcon, Aria) {
         var selectionsElement = $(document.getElementById(state.selectionId));
 
         // Find the active one.
-        var element = selectionsElement.children('[data-active-selection=true]');
+        var element = selectionsElement.children('[data-active-selection]');
         var current = 0;
 
         if (element) {
@@ -817,7 +819,7 @@ function($, log, str, templates, notification, LoadingIcon, Aria) {
             // Find the list of selections.
             var selectionsElement = $(document.getElementById(state.selectionId));
             // Find the active one.
-            var element = selectionsElement.children('[data-active-selection=true]');
+            var element = selectionsElement.children('[data-active-selection]');
             if (!element.length) {
                 return activateSelection(0, state);
             }
@@ -845,7 +847,7 @@ function($, log, str, templates, notification, LoadingIcon, Aria) {
                 case KEYS.SPACE:
                 case KEYS.ENTER:
                     // Get the item that is currently selected.
-                    var selectedItem = $(document.getElementById(state.selectionId)).children('[data-active-selection=true]');
+                    var selectedItem = $(document.getElementById(state.selectionId)).children('[data-active-selection]');
                     if (selectedItem) {
                         e.preventDefault();