Skip to content

Commit

Permalink
fix(List): fix error when ListItem is not HTMLElement (#2672)
Browse files Browse the repository at this point in the history
  • Loading branch information
rivka-ungar authored Dec 22, 2024
1 parent fe1e232 commit e175d32
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/components/List/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const List: VibeComponent<ListProps> & {

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));
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/List/utils/ListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLElement[]>) => {
Expand Down

0 comments on commit e175d32

Please sign in to comment.