Skip to content

Commit eed7343

Browse files
authored
Quick fix for Chromium v140 select issue (#4597)
1 parent 4a5b646 commit eed7343

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

src/js/utils/common.js

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,36 @@ export function urlExists(url) {
9292
*/
9393

9494
$.fn.sortSelect = function (text = "") {
95-
const op = this.children("option");
96-
97-
op.sort((a, b) => {
98-
if (a.text === text) {
99-
return -1;
100-
}
101-
if (b.text === text) {
102-
return 1;
103-
}
104-
return a.text.localeCompare(b.text, window.navigator.language, { ignorePunctuation: true });
95+
this.each(function () {
96+
const select = this;
97+
// Collect option data
98+
const optionData = Array.from(select.options).map(opt => ({
99+
value: opt.value,
100+
text: opt.text,
101+
selected: opt.selected,
102+
disabled: opt.disabled,
103+
}));
104+
105+
// Sort option data
106+
optionData.sort((a, b) => {
107+
if (a.text === text) { return -1; }
108+
if (b.text === text) { return 1; }
109+
return a.text.localeCompare(b.text, window.navigator.language, { ignorePunctuation: true });
110+
});
111+
112+
// Remove all options
113+
while (select.options.length) { select.remove(0); }
114+
115+
// Add sorted options
116+
optionData.forEach(opt => {
117+
const option = document.createElement("option");
118+
option.value = opt.value;
119+
option.text = opt.text;
120+
option.selected = opt.selected;
121+
option.disabled = opt.disabled;
122+
select.add(option);
123+
});
105124
});
106125

107-
return this.empty().append(op);
126+
return this;
108127
};

0 commit comments

Comments
 (0)