Skip to content

Fix: prevent arrow key nav conflict inside textareas #1445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions common-theme/assets/scripts/solo-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ class SoloView extends HTMLElement {
fragment: null,
touchStartX: 0,
touchEndX: 0,
};
// Adding window and doc event listeners
}; // Adding window and doc event listeners
window.addEventListener(
"hashchange",
{ passive: true },
this.handleFragment.bind(this)
this.handleFragment.bind(this),
{ passive: true }
);
// Note: We're keeping document keydown listener for wider page coverage
// but the handler will now check for editable elements
document.addEventListener("keydown", this.handleKeydown.bind(this));
}

Expand Down Expand Up @@ -78,7 +79,11 @@ class SoloView extends HTMLElement {
{ passive: true }
);

this.addEventListener("keydown", this.handleKeydown, { passive: true });
this.addEventListener(
"keydown",
this.handleKeydown,
{ passive: false } // Changed from true to false so we can call preventDefault when appropriate
);
}

// Update current block index
Expand Down Expand Up @@ -118,11 +123,20 @@ class SoloView extends HTMLElement {
this.navigateNext(new Event("swipe"));
}
};

handleKeydown = (event) => {
// Don't intercept arrow keys if they occurred in a form control that uses arrow keys
const target = event.target;
if (target.tagName === 'TEXTAREA' ||
target.tagName === 'INPUT' ||
target.tagName === 'SELECT' ||
target.isContentEditable) {
return; // Allow default behavior for arrow keys in editable elements
}

if (event.key === "ArrowLeft") {
this.navigateBack(event);
}

if (event.key === "ArrowRight") {
this.navigateNext(event);
}
Expand Down