Scenario

Link clicks interfere with contenteditable editing

When a link is inside a contenteditable element, clicking on the link may navigate away or trigger unexpected behavior instead of allowing text editing. The behavior varies across browsers and can make it difficult to edit link text or select links for deletion.

formatting
Scenario ID
scenario-link-click-editing

Details

When a link is inside a contenteditable element, clicking on the link may navigate away or trigger unexpected behavior instead of allowing text editing. The behavior varies across browsers and can make it difficult to edit link text or select links for deletion.

Observed Behavior

  • Chrome/Edge: May navigate to the link URL or allow text selection, behavior inconsistent
  • Firefox: May navigate immediately on click
  • Safari: May navigate or allow editing, behavior varies
  • Chrome/Edge: Usually selects the link text for editing
  • Firefox: May navigate or select text
  • Safari: Behavior inconsistent
  • Chrome/Edge: Shows context menu with link options
  • Firefox: Shows context menu
  • Safari: Shows context menu, but behavior may differ
  • Chrome/Edge: Can be difficult, may trigger navigation
  • Firefox: May navigate before selection is complete
  • Safari: Selection may be interrupted by navigation

Impact

  • Difficulty editing link text
  • Accidental navigation when trying to edit
  • Poor user experience when working with links in editors
  • Need for workarounds to prevent navigation

Browser Comparison

  • Chrome/Edge: Generally better at allowing text selection, but navigation can still occur
  • Firefox: More likely to navigate on click
  • Safari: Behavior is inconsistent

Workaround

Prevent default link behavior and handle clicks manually:

element.addEventListener('click', (e) => {
  const link = e.target.closest('a');
  if (link && e.target.closest('[contenteditable="true"]')) {
    // Prevent navigation
    e.preventDefault();
    
    // Allow text selection on single click
    if (e.detail === 1) {
      // Single click - allow selection
      const selection = window.getSelection();
      const range = document.createRange();
      range.selectNodeContents(link);
      selection.removeAllRanges();
      selection.addRange(range);
    } else if (e.detail === 2) {
      // Double click - start editing
      link.contentEditable = 'true';
      link.focus();
    }
  }
});

// Also prevent navigation on Enter key when link is focused
element.addEventListener('keydown', (e) => {
  if (e.key === 'Enter' && e.target.tagName === 'A') {
    e.preventDefault();
    // Insert line break or create new paragraph
    insertLineBreak(e.target);
  }
});

References

Scenario flow

Visual view of how this scenario connects to its concrete cases and environments. Nodes can be dragged and clicked.

React Flow mini map

Variants

Each row is a concrete case for this scenario, with a dedicated document and playground.

Case OS Device Browser Keyboard Status
ce-0101-link-click-navigation-chrome Windows 11 Desktop or Laptop Any Chrome 120.0 US draft
ce-0142-link-double-click-select Windows 11 Desktop or Laptop Any Chrome 120.0 US draft
ce-0164-link-text-editing-navigates macOS 14.0 Desktop or Laptop Any Safari 17.0 US draft

Browser compatibility

This matrix shows which browser and OS combinations have documented cases for this scenario. Click on a cell to view the specific case.

Confirmed
Draft
No case documented

Cases

Open a case to see the detailed description and its dedicated playground.

Related Scenarios

Other scenarios that share similar tags or category.

Tags: link

Link insertion and editing behavior varies across browsers

When inserting or editing links in contenteditable elements, the behavior varies significantly across browsers. Creating links, editing link text, and removing links can result in unexpected DOM structures or lost formatting.

3 cases
Tags: link

Typing adjacent to formatted elements causes unexpected behavior

When typing text next to formatted elements (links, bold, italic, etc.) in contenteditable, the input events may include the formatted element's text in event.data, selection ranges may include the formatted element, and text may be inserted into the formatted element instead of after it. This occurs across different browsers and input methods.

1 case
Category: formatting

Background color changes behave inconsistently

Changing background color (highlighting) in contenteditable elements behaves inconsistently across browsers. Background colors may be applied as inline styles, may not persist when typing, or may interfere with text selection. The behavior differs from text color changes.

3 cases
Category: formatting

Blockquote editing behavior varies across browsers

Editing text within blockquote elements in contenteditable behaves inconsistently across browsers. Pressing Enter, applying formatting, or pasting content may break the blockquote structure, create nested blockquotes, or behave unexpectedly.

4 cases
Category: formatting

Browser auto-formatting interferes with contenteditable editing

Browsers may automatically format text in contenteditable elements, such as converting URLs to links, capitalizing text, formatting numbers, or applying other transformations. This auto-formatting can interfere with editing, cause cursor positioning issues, and create unwanted markup or style changes.

0 cases

Comments & Discussion

Have questions, suggestions, or want to share your experience? Join the discussion below.