Skip to content

Commit 39df8fa

Browse files
committed
fix(select): optimize control flow for node insertion and update sample title
1 parent 9530f73 commit 39df8fa

2 files changed

Lines changed: 9 additions & 12 deletions

File tree

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -624,21 +624,18 @@ export class IgxSelectComponent extends IgxDropDownComponent implements IgxSelec
624624
}
625625
}
626626

627-
for (let index = 0; index < orderedTopLevelNodes.length; index++) {
627+
let nextReferenceNode: HTMLElement | null = null;
628+
for (let index = orderedTopLevelNodes.length - 1; index >= 0; index--) {
628629
const node = orderedTopLevelNodes[index];
629-
if (container.contains(node)) {
630+
if (node.parentElement === container) {
631+
nextReferenceNode = node;
630632
continue;
631633
}
632-
// Find the next node already in the container and insert before it
633-
// to preserve template order.
634-
let referenceNode: HTMLElement | null = null;
635-
for (let nextIndex = index + 1; nextIndex < orderedTopLevelNodes.length; nextIndex++) {
636-
if (orderedTopLevelNodes[nextIndex].parentElement === container) {
637-
referenceNode = orderedTopLevelNodes[nextIndex];
638-
break;
639-
}
634+
if (container.contains(node)) {
635+
continue;
640636
}
641-
container.insertBefore(node, referenceNode);
637+
container.insertBefore(node, nextReferenceNode);
638+
nextReferenceNode = node;
642639
}
643640
}
644641

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)