Single click on link navigates instead of allowing text selection in Chrome
OS: Windows 11 · Device: Desktop or Laptop Any · Browser: Chrome 120.0 · Keyboard: US
Open case →Scenario
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.
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.
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);
}
});
Visual view of how this scenario connects to its concrete cases and environments. Nodes can be dragged and clicked.
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 |
This matrix shows which browser and OS combinations have documented cases for this scenario. Click on a cell to view the specific case.
| Browser | Windows | macOS |
|---|---|---|
| Chrome | — | |
| Safari | — |
Open a case to see the detailed description and its dedicated playground.
OS: Windows 11 · Device: Desktop or Laptop Any · Browser: Chrome 120.0 · Keyboard: US
Open case →OS: Windows 11 · Device: Desktop or Laptop Any · Browser: Chrome 120.0 · Keyboard: US
Open case →OS: macOS 14.0 · Device: Desktop or Laptop Any · Browser: Safari 17.0 · Keyboard: US
Open case →Other scenarios that share similar tags or category.
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.
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.
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.
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.
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.
Have questions, suggestions, or want to share your experience? Join the discussion below.