Skip to content
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

Hotkeys: prevent contenteditable tags from behaving properly #558

Open
samgaudet opened this issue Feb 23, 2025 · 1 comment
Open

Hotkeys: prevent contenteditable tags from behaving properly #558

samgaudet opened this issue Feb 23, 2025 · 1 comment

Comments

@samgaudet
Copy link

Details

Expected Result

When using contenteditable tags in my documentation, I expect keyboard inputs to be available to a user on my site.

Actual Result

Given ReadTheDocs makes use of several EventListeners for hotkeys, the letter d does not work as expected as a user input in a contenteditable tag.

This has resulted in buggy behavior in a MkDocs plugin I am working on, as documented in the issue here: samgaudet/mkdocs-madlibs#4 (comment)

Reproduce the issue

To reproduce the issue, navigate here, click the editable NAME field, and try to type a name that includes the letter d.

Solution ideation

As far as I have been able to tell, there is not easy way to toggle the EventListener off or remove it for my documentation site. Perhaps one solution may be to allow for easier configuration of EventListeners and/or hotkeys from within a Read the Docs project's configuration/settings?

@humitos
Copy link
Member

humitos commented Feb 24, 2025

When using contenteditable tags in my documentation

Interesting. I wasn't aware of this attribute. Link for reference https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/contenteditable

We should modify our code at

addons/src/hotkeys.js

Lines 53 to 77 in 1950a82

if (
this.docDiffHotKeyEnabled &&
keyboardEventToString(e) ===
this.config.addons.hotkeys.doc_diff.trigger &&
document.activeElement.tagName !== "INPUT" &&
document.activeElement.tagName !== "TEXTAREA" &&
document.activeElement.tagName !== "READTHEDOCS-SEARCH"
) {
if (this.docDiffEnabled) {
event = new CustomEvent(EVENT_READTHEDOCS_DOCDIFF_HIDE);
} else {
event = new CustomEvent(EVENT_READTHEDOCS_DOCDIFF_ADDED_REMOVED_SHOW);
}
}
// Search
if (
this.searchHotKeyEnabled &&
keyboardEventToString(e) === this.config.addons.hotkeys.search.trigger &&
document.activeElement.tagName !== "INPUT" &&
document.activeElement.tagName !== "TEXTAREA" &&
document.activeElement.tagName !== "READTHEDOCS-SEARCH"
) {
event = new CustomEvent(EVENT_READTHEDOCS_SEARCH_SHOW);
}
to support contenteditable and skip triggering our events in that case.

@humitos humitos transferred this issue from readthedocs/readthedocs.org Feb 24, 2025
@github-project-automation github-project-automation bot moved this to Planned in 📍Roadmap Feb 24, 2025
@humitos humitos changed the title ReadTheDocs default EventListeners prevent contenteditable tags from behaving properly Hotkeys: prevent contenteditable tags from behaving properly Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Planned
Development

No branches or pull requests

2 participants