Skip to content

Fix Cmd/Ctrl-click on sub-page links not opening new tab - #5928

Merged
falkoschindler merged 2 commits into
mainfrom
fix/sub-pages-modifier-click
Apr 1, 2026
Merged

Fix Cmd/Ctrl-click on sub-page links not opening new tab#5928
falkoschindler merged 2 commits into
mainfrom
fix/sub-pages-modifier-click

Conversation

@falkoschindler

Copy link
Copy Markdown
Contributor

Motivation

When using ui.link inside a ui.sub_pages context, Cmd-click (macOS) or Ctrl-click (Windows/Linux) does not open the link in a new browser tab. Instead, the click is intercepted by the sub-pages router and the navigation happens in the same tab. This breaks the standard browser behavior users expect from modifier-key clicks on links.

def root():
    ui.sub_pages({
        '/': lambda: ui.link('Go to other page', '/other'),
        '/other': lambda: ui.label('This is the other page'),
    })

Implementation

The global click event listener in sub_pages.js calls e.preventDefault() for all clicks on internal links (those starting with /) to handle client-side routing. However, it did not check for modifier keys before intercepting.

The fix adds an early return when any modifier key (metaKey, ctrlKey, shiftKey, altKey) is held during the click, allowing the browser to handle these events natively (e.g., open in new tab, open in new window, download).

Progress

  • The PR title is a short phrase starting with a verb like "Add ...", "Fix ...", "Update ...", "Remove ...", etc.
  • The implementation is complete.
  • This PR does not address a security issue.
  • Pytests have been added.
  • Documentation is not necessary.
  • No breaking changes to the public API.

falkoschindler and others added 2 commits April 1, 2026 21:22
The global click handler in sub_pages.js was intercepting all clicks on
internal links, including modifier-key clicks (Cmd, Ctrl, Shift, Alt),
preventing the browser from opening links in a new tab or window.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@falkoschindler falkoschindler added bug Type/scope: Incorrect behavior in existing functionality review Status: PR is open and needs review labels Apr 1, 2026
@falkoschindler falkoschindler added this to the 3.10 milestone Apr 1, 2026
@falkoschindler
falkoschindler requested a review from evnchn April 1, 2026 19:29

@evnchn evnchn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I was wondering where's the coverage for the "Windows key" (Windows) and "Super key" (for Linux). Turns out both in metaKey, so yeah we got all keys.

Claude Code is saying that typically SPA do not exclude alt-click, but I think we should, since we have nothing to do with alt-click and we should not "occupy" it as such.

It'd be a different story if we want to add alt-click function, which I don't see in the long-term future.

@falkoschindler
falkoschindler added this pull request to the merge queue Apr 1, 2026
Merged via the queue into main with commit ac1c3cd Apr 1, 2026
7 checks passed
@falkoschindler
falkoschindler deleted the fix/sub-pages-modifier-click branch April 1, 2026 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Type/scope: Incorrect behavior in existing functionality review Status: PR is open and needs review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants