Skip to content

Commit

Permalink
Fix ListBox not scrolling to the active item in some circumstances (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwooding authored Jul 26, 2024
1 parent ffc0dd4 commit 31c3702
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/pretty-feet-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@salt-ds/core": patch
---

Fixed ListBox not scrolling to the active item in some circumstances
17 changes: 4 additions & 13 deletions packages/core/src/list-control/ListControlState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,19 +322,10 @@ export function useListControl<Item>(props: ListControlProps<Item>) {
return;
}

const { scrollTop } = listRef.current;
const { offsetTop, offsetHeight } = activeElement;

const isVisible =
offsetTop >= scrollTop &&
offsetTop + offsetHeight <= scrollTop + listRef.current.offsetHeight;

if (!isVisible) {
activeElement.scrollIntoView({
block: "end",
inline: "nearest",
});
}
activeElement.scrollIntoView({
block: "nearest",
inline: "nearest",
});
}
}, [activeState]);

Expand Down

0 comments on commit 31c3702

Please sign in to comment.