Skip to content

Commit ff96f81

Browse files
authored
fix(combo): Prevent constant rerender for certain props under React (#1660)
1 parent 40e13e2 commit ff96f81

File tree

5 files changed

+488
-20
lines changed

5 files changed

+488
-20
lines changed

src/components/combo/combo.ts

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
} from '../common/mixins/forms/form-value.js';
2424
import {
2525
asArray,
26+
equal,
2627
findElementFromEventPath,
2728
first,
2829
isEmpty,
@@ -163,10 +164,10 @@ export default class IgcComboComponent<
163164
protected _navigation = new NavigationController<T>(this, this._state);
164165

165166
@queryAssignedElements({ slot: 'suffix' })
166-
protected inputSuffix!: Array<HTMLElement>;
167+
protected inputSuffix!: HTMLElement[];
167168

168169
@queryAssignedElements({ slot: 'prefix' })
169-
protected inputPrefix!: Array<HTMLElement>;
170+
protected inputPrefix!: HTMLElement[];
170171

171172
@query('[part="search-input"]')
172173
protected _searchInput!: IgcInputComponent;
@@ -209,7 +210,11 @@ export default class IgcComboComponent<
209210
*/
210211
@property({ type: Boolean, reflect: true, attribute: 'single-select' })
211212
public set singleSelect(value: boolean) {
212-
this._singleSelect = value;
213+
if (this._singleSelect === Boolean(value)) {
214+
return;
215+
}
216+
217+
this._singleSelect = Boolean(value);
213218
this._selection.clear();
214219
if (this.hasUpdated) {
215220
this.updateValue();
@@ -300,8 +305,10 @@ export default class IgcComboComponent<
300305
*/
301306
@property({ attribute: 'group-key' })
302307
public set groupKey(value: Keys<T> | undefined) {
303-
this._groupKey = value;
304-
this._state.runPipeline();
308+
if (this._groupKey !== value) {
309+
this._groupKey = value;
310+
this._state.runPipeline();
311+
}
305312
}
306313

307314
public get groupKey() {
@@ -316,8 +323,10 @@ export default class IgcComboComponent<
316323
*/
317324
@property({ attribute: 'group-sorting' })
318325
public set groupSorting(value: GroupingDirection) {
319-
this._groupSorting = value;
320-
this._state.runPipeline();
326+
if (this._groupSorting !== value) {
327+
this._groupSorting = value;
328+
this._state.runPipeline();
329+
}
321330
}
322331

323332
public get groupSorting() {
@@ -334,8 +343,11 @@ export default class IgcComboComponent<
334343
*/
335344
@property({ type: Object, attribute: 'filtering-options' })
336345
public set filteringOptions(value: Partial<FilteringOptions<T>>) {
337-
this._filteringOptions = { ...this._filteringOptions, ...value };
338-
this._state.runPipeline();
346+
const options = { ...this._filteringOptions, ...value };
347+
if (!equal(options, this._filteringOptions)) {
348+
this._filteringOptions = options;
349+
this._state.runPipeline();
350+
}
339351
}
340352

341353
public get filteringOptions(): FilteringOptions<T> {
@@ -443,7 +455,9 @@ export default class IgcComboComponent<
443455

444456
private _rootClickController = addRootClickHandler(this, {
445457
hideCallback: async () => {
446-
if (!this.handleClosing()) return;
458+
if (!this.handleClosing()) {
459+
return;
460+
}
447461
this.open = false;
448462

449463
await this.updateComplete;
@@ -668,7 +682,7 @@ export default class IgcComboComponent<
668682

669683
/** Shows the list of options. */
670684
public async show(): Promise<boolean> {
671-
return this._show(false);
685+
return await this._show(false);
672686
}
673687

674688
protected async _hide(emitEvent = true) {
@@ -688,7 +702,7 @@ export default class IgcComboComponent<
688702

689703
/** Hides the list of options. */
690704
public async hide(): Promise<boolean> {
691-
return this._hide(false);
705+
return await this._hide(false);
692706
}
693707

694708
protected _toggle(emit = true) {
@@ -697,7 +711,7 @@ export default class IgcComboComponent<
697711

698712
/** Toggles the list of options. */
699713
public async toggle(): Promise<boolean> {
700-
return this._toggle(false);
714+
return await this._toggle(false);
701715
}
702716

703717
private _getActiveDescendantId(index: number) {

0 commit comments

Comments
 (0)