MDL-68167 lib: autocomplete focos should not be removed on blur

See https://www.w3.org/TR/wai-aria-practices-1.1/examples/listbox/listbox-rearrangeable.html
This commit is contained in:
Shamim Rezaie 2020-10-30 02:54:38 +11:00
parent e2ee6025fe
commit 0438cd60bb
3 changed files with 10 additions and 13 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -812,17 +812,14 @@ function($, log, str, templates, notification, LoadingIcon, Aria) {
// Remove it from the selection. // Remove it from the selection.
pendingPromise.resolve(deselectItem(options, state, $(e.currentTarget), originalSelect)); pendingPromise.resolve(deselectItem(options, state, $(e.currentTarget), originalSelect));
}); });
// Remove the highlight of items when user tabs out the tag list. // When listbox is focused, focus on the first option if there is no focused option.
selectionElement.on('blur', function(e) { selectionElement.on('focus', function() {
e.preventDefault(); // Find the list of selections.
$(this).children().attr('data-active-selection', false).attr('id', ''); var selectionsElement = $(document.getElementById(state.selectionId));
}); // Find the active one.
// When tag list is focused, highlight the first item. var element = selectionsElement.children('[data-active-selection=true]');
selectionElement.on('focus', function(e) { if (!element.length) {
e.preventDefault(); return activateSelection(0, state);
var element = $(this).children('[data-active-selection=true]');
if (element && element.length === 0) {
activateNextSelection(state);
} }
}); });
// Keyboard navigation for the selection list. // Keyboard navigation for the selection list.