Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The list doesn't scroll to the top on input #63

Open
Khavrolev opened this issue Dec 18, 2024 · 1 comment
Open

The list doesn't scroll to the top on input #63

Khavrolev opened this issue Dec 18, 2024 · 1 comment

Comments

@Khavrolev
Copy link

When you start typing country's name, the list doesn't scroll to the top. It leads to some UX problems

Monosnap.screencast.2024-12-18.17-46-26.mp4
@MDmubarak786
Copy link

` // Use state to force re-render of the list when search changes
const [searchValue, setSearchValue] = React.useState("")
const scrollAreaRef = React.useRef(null)

// Find the actual scrollable element within the ScrollArea component
const resetScroll = React.useCallback(() => {
// Allow a small delay for the DOM to update
setTimeout(() => {
if (scrollAreaRef.current) {
// Find the scrollable element (usually has overflow-y: auto/scroll)
const scrollableElement = scrollAreaRef.current.querySelector(
"[data-radix-scroll-area-viewport]"
)
if (scrollableElement) {
;(scrollableElement as HTMLElement).scrollTop = 0
}
}
}, 10)
}, [])
`

<CommandInput placeholder="Search country..." value={searchValue} onValueChange={(value) => { setSearchValue(value) resetScroll() }} />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants