-
Notifications
You must be signed in to change notification settings - Fork 4k
fix(multiselect): preserve scroll position when removing items #13384
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
fix(multiselect): preserve scroll position when removing items #13384
Conversation
Fixes streamlit#13317 - When removing an item from st.multiselect, the scroll position was being reset. This adds scroll position tracking via refs and restores the position using useLayoutEffect. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
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.
Pull request overview
This PR fixes the scroll position reset issue in st.multiselect when removing items. The implementation tracks scroll position via refs and restores it using useLayoutEffect after each render, ensuring a smooth user experience when interacting with multiselect widgets containing many items.
Key changes:
- Added scroll position tracking using refs to store the current scroll position
- Implemented a
useLayoutEffecthook to restore scroll position after renders - Created a custom
ValueContainercomponent override to attach refs and scroll handlers to the BaseWeb select component
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
frontend/lib/src/components/widgets/Multiselect/Multiselect.tsx |
Core implementation: added refs for tracking scroll position, useLayoutEffect to restore position, scroll event handler, and memoized ValueContainer component override |
frontend/lib/src/components/widgets/Multiselect/Multiselect.test.tsx |
Unit test verifying scroll position preservation when removing items using simulated scroll events |
e2e_playwright/st_multiselect_test.py |
End-to-end test validating scroll position preservation in a real browser environment with actual user interactions |
Review Summary: The implementation is well-designed and follows React best practices. The use of useLayoutEffect without dependencies is intentional and correct for this use case, as it needs to synchronously restore scroll position after every render to prevent visual jumps. The memoization of the ValueContainer component and the handleValueContainerScroll callback ensures good performance. Both unit and E2E tests provide appropriate coverage for the fix.
|
Looks great, thanks for the video! Approving from product side, will let the eng team give this a review. |
|
@cursor review |
frontend/lib/src/components/widgets/Multiselect/Multiselect.tsx
Outdated
Show resolved
Hide resolved
SummaryThis PR fixes issue #13317 where the scroll position in Key changes:
Code QualityThe code is well-structured and follows Streamlit's established patterns: Positive aspects:
Implementation details (Multiselect.tsx lines 227-257): useLayoutEffect(() => {
if (valueContainerRef.current) {
valueContainerRef.current.scrollTop = scrollTopRef.current
}
})The The custom ValueContainer component: Test CoverageUnit Tests (Multiselect.test.tsx)✅ Good coverage - The test at lines 511-543:
E2E Tests (st_multiselect_test.py)✅ Good coverage - The test at lines 481-503:
Minor observation: The E2E test uses Python Backwards Compatibility✅ No breaking changes identified
Security & Risk✅ No security concerns identified
Risk assessment: Low. The change is well-scoped and only affects scroll behavior. The RecommendationsNo blocking issues identified. Minor suggestions for consideration:
VerdictAPPROVED: This is a well-implemented bug fix with proper test coverage. The code follows established patterns in the codebase, handles the scroll position preservation correctly using This is an automated AI review. Please verify the feedback and use your judgment. |
sfc-gh-lwilby
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 🚀
|
Thanks for fixing this! Would love to send you a little swag as a thank you, feel free to just fill out this form: |
Fixes #13317 - When removing an item from st.multiselect, the scroll position was being reset. This adds scroll position tracking via refs and restores the position using useLayoutEffect.
Describe your changes
Fixes the scroll position reset issue in
st.multiselectwhen removing anitem. The scroll position is now tracked via refs and restored using
useLayoutEffect.GitHub Issue Link (if applicable)
Fixes #13317
Testing Plan
Multiselect.test.tsxst_multiselect_test.pyScreenshot or video (only for visual changes)
Streamlit.mp4
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.