Files
outline/app/utils/isKeyboardWidget.ts
T
Tom MoorandClaude Opus 5 e65c86a4a3 fix: Suppress global shortcuts when focus is in a keyboard control (#13369)
Single-letter shortcuts such as "m" to move a document were still active
while a menu or dialog held focus, competing with the control's own key
handling. Generalizes the existing text input check to cover any element
inside a widget that handles its own keyboard input.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-09 23:39:37 -04:00

40 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import isTextInput from "./isTextInput";
// ARIA roles for widgets that implement their own keyboard interaction, such as
// arrow key navigation, typeahead, or dismissal. Focus usually sits on a
// descendant of the widget, so ancestors are checked as well.
// https://www.w3.org/WAI/ARIA/apg/patterns/
const widgetRoles = [
"menu",
"menubar",
"listbox",
"combobox",
"tree",
"treegrid",
"grid",
"dialog",
"alertdialog",
"radiogroup",
"slider",
"spinbutton",
];
const widgetSelector = widgetRoles.map((role) => `[role="${role}"]`).join(",");
/**
* Checks whether the given event target is, or is contained by, a control that
* handles its own keyboard input – a text input, or a widget such as a menu,
* listbox, or dialog. Global keyboard shortcuts should not fire while such a
* control holds focus, otherwise they compete with it for the same keys.
*
* @param target the event target to check.
* @returns true if the target handles its own keyboard input.
*/
export function isKeyboardWidget(target: EventTarget | null): boolean {
if (!(target instanceof Element)) {
return false;
}
return isTextInput(target) || !!target.closest(widgetSelector);
}