Implement Two-Tier Escape Key Behavior: Remove Focus from Editable Fields First, Then Dismiss Overlays
#2881
-
-
State changed as build OD-7846 is successful
-
OneDev
changed state to 'Closed' 2 days ago
Previous Value Current Value Open
Closed
| Type |
Improvement
|
| Priority |
Normal
|
| Assignee | |
| Labels |
No labels
|
Issue Votes (0)
Relates to investigation from Issue 2880: Can the Escape key be configured to first blur focus from editable text fields before triggering OneDev's built-in pane visibility shortcut?
Summary
Currently, pressing
Escapein OneDev always triggers overlay dismiss actions (closing modals, sidebars, tooltips, etc.) regardless of whether an editable text field has focus. This breaks a widely expected convention where pressingEscapeshould first cause the focused input to lose focus, allowing keyboard-driven and accessibility workflows to proceed.We propose a two-tier Escape key behavior:
Escapepress (editable element has focus) → the element loses focus; no overlays are dismissed.Escapepress (no editable element has focus) → existing dismiss/close behavior proceeds as normal.Investigation Findings
An investigation into the current Escape key handling in OneDev revealed the following:
Browser Default Clarification
Pressing
Escapedoes not automatically remove focus from<input>/<textarea>elements in Chrome, Firefox, or Safari. This "blur-on-Escape" behavior is an application-level convention, not a browser built-in.Where Escape Is Currently Intercepted
A global
document-levelkeydownhandler inserver-core/.../web/page/base/base.jscallspreventDefault()on every Escape press:Additional Escape handlers exist in the following files, all dismissing UI overlays:
layout.jssidebar-docked)side-info.jsmodal.jsfloating.jssymbol-tooltip.js,source-view.js, etc.None of these handlers call
activeElement.blur()or otherwise cause the focused element to lose focus.Existing Focus-Aware Shortcut Patterns
The bundled jQuery Hotkeys plugin (
server-core/.../web/asset/hotkeys/jquery.hotkeys.js) already implements focus-aware filtering viafilterInputAcceptingElements,filterTextInputs, andfilterContentEditable. However, the Escape dismiss handlers listed above do not use this filter — they listen with raw$(document).on("keydown", ...)and only exclude a few overlay widgets (e.g., flatpickr, select2).Proposed Implementation
In a central Escape handler (or at the start of each existing dismiss handler), check if
document.activeElementis an editable control:<input>,<textarea>,<select>[contenteditable]If an editable element has focus:
activeElement.blur()(or equivalent) to remove focus.returnearly — do not proceed with overlay dismissal.If no editable element has focus:
Reuse the focus-checking logic already present in the jQuery Hotkeys plugin (
filterInputAcceptingElements/filterTextInputs/filterContentEditable) to maintain consistency.Design Caveats to Consider
Acceptance Criteria
Escapewhile an editable text field has focus causes that field to lose focus without dismissing any overlays.Escapeagain (with no editable field focused) triggers the existing dismiss/close behavior (modals, sidebars, tooltips, etc.).