Skip to content

Commit 5764736

Browse files
committed
[ch-combo-box-render] Fix rare infinite scroll loop when rendering a large number of items
1 parent 500befe commit 5764736

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/components/combo-box/combo-box.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -889,13 +889,14 @@ export class ChComboBoxRender
889889
SELECTED_ITEM_SELECTOR
890890
) as HTMLElement | undefined;
891891

892-
// Focus the selected element to force the scroll into view
892+
// Don't use focus, use scrollIntoView to avoid focus stealing and race
893+
// conditions
893894
if (selectedElement) {
894-
// Wait until the JS has been executed to avoid race conditions when
895-
// rendering elements in the top layer and trying to focus them
896-
requestAnimationFrame(() => {
897-
selectedElement.focus();
898-
this.#inputRef.focus();
895+
selectedElement.scrollIntoView({
896+
block: "nearest",
897+
// @ts-expect-error This property is widely supported but not in the
898+
// lib.dom.ts
899+
container: "nearest"
899900
});
900901
}
901902
}

0 commit comments

Comments
 (0)