Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.

Commit bcfcf29

Browse files
fix(SelectV2): scroll element into view when using arrow keys
This makes sure that we don't use the native element scrolling behavior but rather scroll to an element when it's getting focussed. This makes the scrolling behavior using arrow keys a bit nicer.
1 parent d37b07e commit bcfcf29

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

src/components/SelectV2/DesktopDropdown.tsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,34 @@ export const DesktopDropdown = ({
145145
setFocussed(options.length - 1)
146146
break
147147
case 'ArrowUp':
148-
setFocussed(focussed => Math.max(0, focussed - 1))
148+
event.preventDefault()
149+
150+
setFocussed(previousFocussed => {
151+
const focussed = Math.max(0, previousFocussed - 1)
152+
153+
scrollIntoView(listbox.children[focussed], {
154+
boundary: listbox,
155+
scrollMode: 'always',
156+
block: 'nearest',
157+
})
158+
159+
return focussed
160+
})
149161
break
150162
case 'ArrowDown':
151-
setFocussed(focussed =>
152-
Math.min(options.length - 1, focussed + 1)
153-
)
163+
event.preventDefault()
164+
165+
setFocussed(prevFocussed => {
166+
const focussed = Math.min(options.length - 1, prevFocussed + 1)
167+
168+
scrollIntoView(listbox.children[focussed], {
169+
boundary: listbox,
170+
scrollMode: 'always',
171+
block: 'nearest',
172+
})
173+
174+
return focussed
175+
})
154176
break
155177
case 'Escape':
156178
setOpen(false)

0 commit comments

Comments
 (0)