Skip to content

Web: onLinkPress swallows cmd/ctrl/shift-click, so links can't open in a new tab #1084

Open

Description

@ericpoulinnz

Version: react-native-enriched-markdown 1.1.1

When onLinkPress is set, LinkRenderer calls event.preventDefault() and onLinkPress for every click. The docs recommend onLinkPress for in-app navigation, since target isn't configurable on web, but then cmd/ctrl-click (open in new tab) and shift-click (new window) stop working. Users lose standard browser behaviour on what are real <a href> links. (Middle-click is unaffected, since it fires auxclick, not click.)

Suggested fix: follow the convention web routers use (React Navigation's useLinkProps, React Router's and Next.js's Link): handle only plain primary clicks, and leave modified clicks to the browser. Links the browser can't open, such as custom-scheme mentions (user://…), keep going to onLinkPress:

const BROWSER_SCHEME = /^(https?:|mailto:|\/|#|\?)/i;

const handleClick = (event: MouseEvent) => {
  const isModified = event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || event.button !== 0;
  if (isModified && BROWSER_SCHEME.test(url)) {
    return; // the browser opens it as it would any link
  }
  if (callbacks.onLinkPress) {
    event.preventDefault();
    callbacks.onLinkPress({ url });
  }
};

This needs no new API. Plain clicks behave exactly as today.

Activity

  1. eszlamczyk commented on Oct 26, 2026

    @eszlamczyk
    Collaborator

    Hi @ericpoulinnz, thanks for the report! Leaving modified clicks to the browser sounds right, and it should be an easy fix. This should be fixed before the next minor release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdomain: textEnrichedMarkdownText componenthelp wantedExtra attention is neededlibrary: react-nativeTasks that are specifically for react-native-enriched-markdownplatform: webAffects the web platformpriority: low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions