Skip to content

Commit 624e05d

Browse files
committed
fix(select): optimize control flow for node insertion and update sample title
1 parent 597b3f8 commit 624e05d

2 files changed

Lines changed: 9 additions & 12 deletions

File tree

projects/igniteui-angular/src/lib/select/select.component.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -663,21 +663,18 @@ export class IgxSelectComponent extends IgxDropDownComponent implements IgxSelec
663663
}
664664
}
665665

666-
for (let index = 0; index < orderedTopLevelNodes.length; index++) {
666+
let nextReferenceNode: HTMLElement | null = null;
667+
for (let index = orderedTopLevelNodes.length - 1; index >= 0; index--) {
667668
const node = orderedTopLevelNodes[index];
668-
if (container.contains(node)) {
669+
if (node.parentElement === container) {
670+
nextReferenceNode = node;
669671
continue;
670672
}
671-
// Find the next node already in the container and insert before it
672-
// to preserve template order.
673-
let referenceNode: HTMLElement | null = null;
674-
for (let nextIndex = index + 1; nextIndex < orderedTopLevelNodes.length; nextIndex++) {
675-
if (orderedTopLevelNodes[nextIndex].parentElement === container) {
676-
referenceNode = orderedTopLevelNodes[nextIndex];
677-
break;
678-
}
673+
if (container.contains(node)) {
674+
continue;
679675
}
680-
container.insertBefore(node, referenceNode);
676+
container.insertBefore(node, nextReferenceNode);
677+
nextReferenceNode = node;
681678
}
682679
}
683680

src/app/select/select.sample.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ <h1 class="select-sample__title">Select - disabled item</h1>
103103
</section>
104104

105105
<section class="select-sample__section">
106-
<h1 class="select-sample__title">TEST: &#64;if/&#64;else inside &#64;for</h1>
106+
<h1 class="select-sample__title">Select - &#64;if/&#64;else inside &#64;for</h1>
107107
<igx-select #nestedTest [placeholder]="'Pick One'">
108108
<label igxLabel>Odd/Even Select</label>
109109
@for (item of testItems; track item; let e = $even) {

0 commit comments

Comments
 (0)