From e175d326cab32d8a0d8e3d812689b8d8397aba56 Mon Sep 17 00:00:00 2001 From: Rivka Ungar Date: Sun, 22 Dec 2024 16:31:53 +0200 Subject: [PATCH] fix(List): fix error when ListItem is not HTMLElement (#2672) --- packages/core/src/components/List/List.tsx | 2 +- packages/core/src/components/List/utils/ListUtils.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/components/List/List.tsx b/packages/core/src/components/List/List.tsx index 9f48d044a0..6710420c7a 100644 --- a/packages/core/src/components/List/List.tsx +++ b/packages/core/src/components/List/List.tsx @@ -117,7 +117,7 @@ const List: VibeComponent & { useEffect(() => { const selectedItemIndex = childrenRefs.current.findIndex( - child => isListItem(child) && child?.getAttribute("aria-selected") === "true" + child => child instanceof HTMLElement && isListItem(child) && child?.getAttribute("aria-selected") === "true" ); if (selectedItemIndex !== -1) { updateFocusedItem(getListItemIdByIndex(childrenRefs, selectedItemIndex)); diff --git a/packages/core/src/components/List/utils/ListUtils.ts b/packages/core/src/components/List/utils/ListUtils.ts index 443fa0d3be..e3560738f0 100644 --- a/packages/core/src/components/List/utils/ListUtils.ts +++ b/packages/core/src/components/List/utils/ListUtils.ts @@ -37,7 +37,7 @@ export const getListItemComponentType = (listComponent: ListElement): ListItemEl }; export const isListItem = (element: HTMLElement) => { - return element && element.getAttribute("role") === "option"; + return element && element instanceof HTMLElement && element.getAttribute("role") === "option"; }; export const getNextListItemIndex = (currentIndex: number, childrenRefs: MutableRefObject) => {