Skip to content

Commit e66c116

Browse files
committed
Reduce work done for unhighlightAll during on-click handler (batch handler in v11.0.0-rc8 would also have helped) Choices-js#522 Choices-js#599
1 parent f0c8a05 commit e66c116

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## [11.0.0]
4+
5+
### Bug Fixes (from 10.2.0)
6+
* Reduce work done for `unhighlightAll` during on-click handler (batching in v11.0.0-rc8 would also have helped) [#522](https://github.com/Choices-js/Choices/issues/522) [#599](https://github.com/Choices-js/Choices/issues/599)
7+
38
## [11.0.0-rc8] (2024-08-23)
49

510
### ⚠ BREAKING CHANGES

src/scripts/choices.ts

+15-18
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ class Choices {
408408
if (!item || !item.id) {
409409
return this;
410410
}
411-
const choice = this._store.choices.find((c) => c.id === item.id);
411+
const choice = this._store.items.find((c) => c.id === item.id);
412412
if (!choice || choice.highlighted) {
413413
return this;
414414
}
@@ -426,7 +426,7 @@ class Choices {
426426
if (!item || !item.id) {
427427
return this;
428428
}
429-
const choice = this._store.choices.find((c) => c.id === item.id);
429+
const choice = this._store.items.find((c) => c.id === item.id);
430430
if (!choice || !choice.highlighted) {
431431
return this;
432432
}
@@ -442,15 +442,23 @@ class Choices {
442442

443443
highlightAll(): this {
444444
this._store.withTxn(() => {
445-
this._store.items.forEach((item) => this.highlightItem(item));
445+
this._store.items.forEach((item) => {
446+
if (!item.highlighted) {
447+
this.highlightItem(item);
448+
}
449+
});
446450
});
447451

448452
return this;
449453
}
450454

451455
unhighlightAll(): this {
452456
this._store.withTxn(() => {
453-
this._store.items.forEach((item) => this.unhighlightItem(item));
457+
this._store.items.forEach((item) => {
458+
if (item.highlighted) {
459+
this.unhighlightItem(item);
460+
}
461+
});
454462
});
455463

456464
return this;
@@ -1957,14 +1965,9 @@ class Choices {
19571965
this.hideDropdown();
19581966
}
19591967
} else {
1960-
const hasHighlightedItems = !!this._store.highlightedActiveItems.length;
1961-
1962-
if (hasHighlightedItems) {
1963-
this.unhighlightAll();
1964-
}
1965-
19661968
containerOuter.removeFocusState();
19671969
this.hideDropdown(true);
1970+
this.unhighlightAll();
19681971
}
19691972
}
19701973

@@ -2007,17 +2010,13 @@ class Choices {
20072010
const blurWasWithinContainer = target && containerOuter.element.contains(target as Node);
20082011

20092012
if (blurWasWithinContainer && !this._isScrollingOnIe) {
2010-
const { activeChoices } = this._store;
2011-
const hasHighlightedItems = activeChoices.some((item) => item.highlighted);
20122013
const targetIsInput = target === this.input.element;
20132014
const blurActions = {
20142015
[TEXT_TYPE]: (): void => {
20152016
if (targetIsInput) {
20162017
containerOuter.removeFocusState();
2017-
if (hasHighlightedItems) {
2018-
this.unhighlightAll();
2019-
}
20202018
this.hideDropdown(true);
2019+
this.unhighlightAll();
20212020
}
20222021
},
20232022
[SELECT_ONE_TYPE]: (): void => {
@@ -2030,9 +2029,7 @@ class Choices {
20302029
if (targetIsInput) {
20312030
containerOuter.removeFocusState();
20322031
this.hideDropdown(true);
2033-
if (hasHighlightedItems) {
2034-
this.unhighlightAll();
2035-
}
2032+
this.unhighlightAll();
20362033
}
20372034
},
20382035
};

0 commit comments

Comments
 (0)