Input events fire on focus/blur without content changes
OS: Android 10+ · Device: Mobile Any · Browser: Chrome for Android 90+ · Keyboard: Any
Open case →Scenario
In Chrome on Android, input events may fire when a contenteditable element gains or loses focus, even without content changes. This behavior can lead to unintended side effects in applications relying on input events for content modification detection.
In Chrome on Android, input events may fire when a contenteditable element gains or loses focus, even without any actual content changes. This behavior can lead to unintended side effects in applications that rely on input events to detect content modifications.
The issue occurs when:
contenteditable element gains focus (user taps on it)input event fires even though no content was changedinput event may fireinput events may trigger unnecessary actionsconst editor = document.querySelector('[contenteditable]');
let lastContent = editor.innerHTML;
let isFocusing = false;
let isBlurring = false;
editor.addEventListener('focus', () => {
isFocusing = true;
lastContent = editor.innerHTML;
// Reset flag after a short delay
setTimeout(() => {
isFocusing = false;
}, 100);
});
editor.addEventListener('blur', () => {
isBlurring = true;
// Reset flag after a short delay
setTimeout(() => {
isBlurring = false;
}, 100);
});
editor.addEventListener('input', (e) => {
// Ignore input events during focus/blur
if (isFocusing || isBlurring) {
return;
}
// Check if content actually changed
const currentContent = editor.innerHTML;
if (currentContent === lastContent) {
// Content didn't change, ignore this event
return;
}
// Content actually changed, process the event
lastContent = currentContent;
handleContentChange(currentContent);
});
const editor = document.querySelector('[contenteditable]');
let isUserInput = false;
// Track user input
editor.addEventListener('beforeinput', () => {
isUserInput = true;
});
editor.addEventListener('input', () => {
isUserInput = false;
});
// Use MutationObserver to detect actual DOM changes
const observer = new MutationObserver((mutations) => {
// Only process if it was user input
if (isUserInput) {
handleContentChange(editor.innerHTML);
}
});
observer.observe(editor, {
childList: true,
subtree: true,
characterData: true
});
const editor = document.querySelector('[contenteditable]');
let inputTimeout;
editor.addEventListener('input', (e) => {
// Clear previous timeout
clearTimeout(inputTimeout);
// Debounce input events
inputTimeout = setTimeout(() => {
const currentContent = editor.innerHTML;
handleContentChange(currentContent);
}, 150);
});
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-0312-chrome-android-focus-blur-input-en | Android 10+ | Mobile Any | Chrome for Android 90+ | Any | draft |
Open a case to see the detailed description and its dedicated playground.
OS: Android 10+ · Device: Mobile Any · Browser: Chrome for Android 90+ · Keyboard: Any
Open case →Other scenarios that share similar tags or category.
The enterkeyhint attribute, which controls the label on the Enter key on mobile keyboards, does not work on contenteditable elements. The Enter key label remains the default regardless of the attribute value.
On iOS, contenteditable elements may become non-selectable or non-editable. Tapping on the element doesn't display the caret, preventing text input.
On iOS Safari, touch events (tap, long-press) on a contenteditable region may not properly focus the element. The virtual keyboard may not appear, or focus may be lost unexpectedly.
Samsung keyboard's text prediction feature causes various input event handling issues in contenteditable elements on Android Chrome, including insertCompositionText events, missing getTargetRanges(), selection mismatches, and combined event.data when typing adjacent to links or formatted elements.
When a contenteditable element has CSS backdrop-filter applied, rendering may be affected. Text may appear blurry, selection may not render correctly, and performance may be degraded, especially on mobile devices.
Have questions, suggestions, or want to share your experience? Join the discussion below.