Repository navigation
fix(ui): scroll only CMenu's own list when it shows the focused item - #395
Merged
Merged
Conversation
CMenu brought its focused item into view with scrollIntoView, which also scrolls the page and any page that holds this one in a frame. It does that each time it updates its list of items, such as after a re-render or after the pointer leaves a submenu trigger, so a reader who scrolled the page with a submenu open was pulled back to the menu. On the docs menu page, with Chromium 156, the page snapped back on every scroll, and the docs end-to-end test that then clicks a preview far up the page timed out. The menu now scrolls only the scrollable elements between the item and the menu's popup, measured against their visible area inside the border. A key press that moves focus to an item still off screen, as in a menu taller than the viewport at high zoom, also scrolls the page, since the menu takes the keys a reader would scroll with. CContextMenu and CSplitButton use the same menu code and get the same fix. Left for a follow-up: CSelect, CMultiSelect, CCombobox (through the shared active-option code) and CTabs also call scrollIntoView on paths that run without a key press, such as a re-render while open or options that arrive late, so they can pull the page back the same way. Fixes #383 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 25, 2026
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 #383.
Cause
CMenushowed its focused item withentry.element.scrollIntoView({ block: "nearest" }). That call scrolls every scrolling ancestor: the menu's list, the page, and any page that holds this one in a frame.The menu calls it each time it updates its list of items, not only after a key press. That includes a re-render, a settings change, and a submenu that closes when the pointer leaves its trigger.
So with a submenu open, scrolling the page moved the pointer off the submenu trigger. The menu then updated, refocused its item, and scrolled the page straight back.
On the docs menu page with Chromium 156 (Playwright 1.64.1), this happened on every scroll. The docs e2e test
test_menu_ui_examples_cover_choices_submenus_control_and_themeopens the nested-submenu demo and then clicks a preview about 4,000 px up the page. The page kept snapping back, Chromium runs no animation frames in an offscreen iframe, and Playwright's click waited forever. With Playwright 1.62.0, the same test passed on current main.Fix
focusEntryscrolls only the scrollable elements between the item and the menu's popup (revealInSurface). It measures their visible area inside the border, beside any scrollbar, and scrolls by the least distance, asblock: "nearest"does.keyboardRevealflag is set while the key handler runs. A key that opens the menu carries that permission with its open request, because the menu focuses its first or last item after the handler returns. Nothing else scrolls the page.CContextMenuandCSplitButtonuse the same menu code, so they get the fix too.Known limits:
CContextMenuopened with Shift+F10 opens from thecontextmenuevent, not the key handler, so it scrolls only inside the menu. I didn't verify this path.Left for a follow-up (same class of bug)
These components call
scrollIntoViewon paths that run without a key press, so they can pull the page back the same way:CSelect(runtime.source.js:350) andCMultiSelect: when a server re-render reopens an open popup.CCombobox, through_active_descendant.py:140: when lateloadOptionsresults arrive or the server pushes new items.CTabs(ctabs.py:591): when a re-render removes the current tab.Not checked:
focus()calls withoutpreventScrollinCTagandCToolbaron re-render paths.These are separate components, two of them with built runtimes, so I kept this PR to the menu.
Tests
Four new browser tests in
cmenu/tests/e2e/test_cmenu_e2e.py:test_an_open_menu_does_not_scroll_the_page_back_to_itself: a settings change while the page is scrolled away.test_scrolling_the_page_while_a_submenu_is_open_keeps_its_position: the reported path, with the pointer resting on a submenu trigger.test_a_key_scrolls_the_page_to_an_item_below_the_screen[end, open-on-last]: a 320x256 viewport.test_keyboard_moves_reveal_items_inside_a_menu_that_scrolls: measured inside the border.The first two fail on main. The key and border tests fail against an earlier draft of this change that never scrolled the page.
Evidence (local)
--platform linux), pyright, citry-client, codemirror Fluent, the protocol phases, the events protocol JS, vscode-extension, citry-ui assets and the validators.docs-playgroundfails on main too: the committeddocs_site/static/playground/portable_ide.pyis stale since perf: walk parsed templates in check and the LSP without one Python call per level #377. This PR doesn't touch it.PR CI runs the cargo phases and the full matrix.
🤖 Generated with Claude Code