Backport unreleased fix for Tom select

github.com/orchidjs/tom-select/issues/455
I found the bug in Tom Select. Connected with the author and got it fixed. It is unknown when the next release will be so this is the current fix.
This commit is contained in:
William Karsten 2022-09-20 15:19:48 -05:00
parent 6382b00c51
commit b1c05eed8e
1 changed files with 18 additions and 16 deletions

View File

@ -2849,22 +2849,27 @@
refreshOptions(triggerDropdown = true) { refreshOptions(triggerDropdown = true) {
var i, j, k, n, optgroup, optgroups, html, has_create_option, active_value, active_group; var i, j, k, n, optgroup, optgroups, html, has_create_option, active_group;
var create; var create;
const groups = {}; const groups = {};
const groups_order = []; const groups_order = [];
var self = this; var self = this;
var query = self.inputValue(); var query = self.inputValue();
const same_query = query === self.lastQuery || (query == '' && self.lastQuery == null);
var results = self.search(query); var results = self.search(query);
var active_option = null; //self.activeOption; var active_option = null;
var show_dropdown = self.settings.shouldOpen || false; var show_dropdown = self.settings.shouldOpen || false;
var dropdown_content = self.dropdown_content; var dropdown_content = self.dropdown_content;
if (self.activeOption) { if( same_query ){
active_value = self.activeOption.dataset.value; active_option = self.activeOption;
active_group = self.activeOption.closest('[data-group]'); if( active_option ){
} // build markup active_group = active_option.closest('[data-group]');
}
}
// build markup
n = results.items.length; n = results.items.length;
@ -2912,18 +2917,15 @@
}); });
option_el.classList.add('ts-cloned'); option_el.classList.add('ts-cloned');
removeClasses(option_el, 'active'); removeClasses(option_el, 'active');
} // make sure we keep the activeOption in the same group // make sure we keep the activeOption in the same group
if (!active_option && active_value == opt_value) { if (self.activeOption && self.activeOption.dataset.value == opt_value) {
if (active_group) { if (active_group && active_group.dataset.group === optgroup.toString()) {
if (active_group.dataset.group === optgroup) { active_option = option_el;
active_option = option_el; }
} }
} else { }
active_option = option_el;
}
}
groups[optgroup].appendChild(option_el); groups[optgroup].appendChild(option_el);
} }