-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: center active mode in selector dropdown on open #7883
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
Conversation
- Added refs to track selected item and scroll container - Implemented scroll-to-center logic when popover opens - Selected mode now appears centered in viewport instead of list starting at top - Fixes issue where users had to manually scroll to find active mode Fixes #7882
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewing my own code is like debugging in a mirror - everything looks backwards but the bugs are still mine.
| const itemHeight = item.offsetHeight | ||
|
|
||
| // Center the item in the container | ||
| const scrollPosition = itemTop - containerHeight / 2 + itemHeight / 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be valuable to add test coverage for this scroll-to-center behavior? I notice the existing tests don't verify that the selected item is actually scrolled into view when the dropdown opens.
| const item = selectedItemRef.current | ||
|
|
||
| // Calculate positions | ||
| const containerHeight = container.clientHeight |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider extracting this scroll calculation logic into a utility function like scrollItemToCenter(container, item) for better testability and reusability. This would also make the component logic cleaner.
- Replace setTimeout with requestAnimationFrame for more reliable DOM synchronization - Add proper boundary checking to prevent scrolling past container limits - Ensure scroll position stays within valid bounds using Math.min/max
daniel-lxs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Summary
This PR attempts to address Issue #7882 by implementing auto-scroll functionality for the mode selector dropdown.
Problem
When opening the mode selector dropdown, the list always started at the top, requiring users to manually scroll to find the currently active mode, especially problematic when the active mode was far down the list.
Solution
Added scroll-to-center logic that automatically centers the active mode in the viewport when the dropdown opens:
Changes
webview-ui/src/components/chat/ModeSelector.tsx:selectedItemRefandscrollContainerRefrefsTesting
Review Confidence
Code review completed with 95% confidence - implementation is clean and follows existing patterns.
Fixes #7882
Feedback and guidance are welcome!
Important
Centers active mode in
ModeSelector.tsxdropdown on open using scroll-to-center logic.ModeSelector.tsx.selectedItemRefandscrollContainerRefto track elements.useEffect.selectedItemRefandscrollContainerRefrefs.useEffectto calculate and set scroll position.This description was created by
for 268e6c5. You can customize this summary. It will automatically update as commits are pushed.