timc1/kbar

Allowing shortcuts to override default options in shouldRejectKeystrokes

devinsimmons opened this issue · 1 comments

Hello, I'm currently working on a project where we'd like to be able to allow a specific shortcut to run while an input element is focused. Currently, it looks like there's no way to do this, as the shouldRejectKeystrokes util function has 'input' hardcoded as an element type that will always reject keystrokes:

kbar/src/utils.ts

Lines 101 to 122 in 15c7473

export function shouldRejectKeystrokes(
{
ignoreWhenFocused,
}: {
ignoreWhenFocused: string[];
} = { ignoreWhenFocused: [] }
) {
const inputs = ["input", "textarea", ...ignoreWhenFocused].map((el) =>
el.toLowerCase()
);
const activeElement = document.activeElement;
const ignoreStrokes =
activeElement &&
(inputs.indexOf(activeElement.tagName.toLowerCase()) !== -1 ||
activeElement.attributes.getNamedItem("role")?.value === "textbox" ||
activeElement.attributes.getNamedItem("contenteditable")?.value ===
"true");
return ignoreStrokes;
}

Is there a way around this? If not, I'd be happy to contribute a PR myself.

Hey! This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.