Fix ToolStripDropDownMenu scroll boundary issues#14532
Open
LeafShi1 wants to merge 6 commits intodotnet:mainfrom
Open
Fix ToolStripDropDownMenu scroll boundary issues#14532LeafShi1 wants to merge 6 commits intodotnet:mainfrom
LeafShi1 wants to merge 6 commits intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes ToolStripDropDownMenu scrolling boundary logic so the scroll buttons reflect the actual scroll mechanics (advancing the “first displayed item”), including correctly skipping unavailable/hidden items.
Changes:
- Updates
UpdateScrollButtonStatus()to enable Up/Down based on whether a previous/next scrollable item exists relative to_indexOfFirstDisplayedItem. - Updates
ScrollInternal(bool up)to scroll to the previous/next scrollable item (skipping unavailable items) via new helper methods. - Adjusts/adds unit tests covering the regression scenario and unavailable interleaved items.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripDropDownMenu.cs |
Aligns scroll-button enablement and scroll stepping with “previous/next scrollable item” semantics; skips unavailable items. |
src/test/unit/System.Windows.Forms/ToolStripDropDownMenuTests.cs |
Updates an existing regression test expectation and adds coverage for interleaved unavailable items. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
|
Looks good! Please address the Copilot's suggestion first! |
… and align focused items to viewport top when scroll buttons are visible.
…gn focus to top, wrap-around) and scroll button interaction issues (click-through prevention, hit-test priority).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #14530, #14531
Root Cause
PR #14490 rewrote
UpdateScrollButtonStatus()and disabled the Down scroll button as soon asindexOfLastDisplayedItem == lastAvailableItemIndex. The "last displayed item" was defined as any item that intersects the viewport — including items only partially visible at the bottom edge. As a result, the Down button was disabled one scroll step too early: the last item was already clipped into view, but_indexOfFirstDisplayedItemhad not yet advanced to it.Additionally, the previous implementation did not account for interspersed
Available = falseitems (e.g., items whose Visible property was set to false). Scroll steps could land on an unavailable item, and the boundary indices could be computed incorrectly if hidden items were counted among the candidates.Proposed changes
indexOfLastDisplayedItemtracking. Down button is now enabled ifFindNextScrollableItemIndex(_indexOfFirstDisplayedItem) >= 0, mirroring the actual scroll mechanic inScrollInternal(bool up)which moves _indexOfFirstDisplayedItem forward by one available item.firstAvailableItemIndextracking to correctly skip scroll-button pseudo-items and unavailable items when determining scroll boundaries.Available = false.UpdateScrollButtonStatus()andScrollInternal()to correctly skip over unavailable/hidden items when advancing the scroll anchor, preventing the scroll cursor from getting stuck on an invisible item.FindPreviousScrollableItemIndex/FindNextScrollableItemIndexhelpers instead of naively doing_indexOfFirstDisplayedItem ± 1.Customer Impact
ToolStripDropDownMenuusing the Down Arrow key or scroll buttons without stopping when the last item is only partially visible.Available=falseorVisible=false), preventing navigation from getting stuck on hidden items.Regression?
Risk
Screenshots
Before
When the last item appears within the visible area, the down arrow becomes disabled (grayed out).
Item B is hidden; consequently, clicking the up arrow triggers no scrolling response.
BeforeChanges.mp4
After
When the last item is not the first item in the visible area, the down arrow remains clickable.
Item B is hidden, yet both the up and down arrows remain fully functional.
AfterChanges.mp4
Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow