From be36b76b3443cfe80714ae9cd32db72806acd5ff Mon Sep 17 00:00:00 2001 From: Josh Wooding <12938082+joshwooding@users.noreply.github.com> Date: Fri, 26 Jul 2024 09:54:52 +0100 Subject: [PATCH] Fix ListBox not scrolling to the active item in some circumstances --- .changeset/pretty-feet-dance.md | 5 +++++ .../core/src/list-control/ListControlState.ts | 17 ++++------------- 2 files changed, 9 insertions(+), 13 deletions(-) create mode 100644 .changeset/pretty-feet-dance.md diff --git a/.changeset/pretty-feet-dance.md b/.changeset/pretty-feet-dance.md new file mode 100644 index 00000000000..f7ad9d98b39 --- /dev/null +++ b/.changeset/pretty-feet-dance.md @@ -0,0 +1,5 @@ +--- +"@salt-ds/core": patch +--- + +Fixed ListBox not scrolling to the active item in some circumstances diff --git a/packages/core/src/list-control/ListControlState.ts b/packages/core/src/list-control/ListControlState.ts index 4f5610dbb92..66970747027 100644 --- a/packages/core/src/list-control/ListControlState.ts +++ b/packages/core/src/list-control/ListControlState.ts @@ -322,19 +322,10 @@ export function useListControl(props: ListControlProps) { 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]);