mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-06-26 01:25:22 +02:00
This fixes keyboard shortcuts (Ctrl+S, Ctrl+B, Ctrl+J, Ctrl+K) not working with non-English keyboard layouts (e.g., Russian, French AZERTY, German QWERTZ). Fixes #3495
37 lines
932 B
TypeScript
37 lines
932 B
TypeScript
import { useEffect, useRef } from "react";
|
|
import { Input } from "@/components/ui/input";
|
|
|
|
type Props = React.ComponentPropsWithoutRef<typeof Input>;
|
|
|
|
export const FocusShortcutInput = (props: Props) => {
|
|
const inputRef = useRef<HTMLInputElement | null>(null);
|
|
|
|
useEffect(() => {
|
|
const onKeyDown = (e: KeyboardEvent) => {
|
|
const isMod = e.metaKey || e.ctrlKey;
|
|
if (!isMod || e.code !== "KeyK") return;
|
|
|
|
const target = e.target as HTMLElement | null;
|
|
if (target) {
|
|
const tag = target.tagName;
|
|
if (
|
|
target.isContentEditable ||
|
|
tag === "INPUT" ||
|
|
tag === "TEXTAREA" ||
|
|
tag === "SELECT" ||
|
|
target.getAttribute("role") === "textbox"
|
|
)
|
|
return;
|
|
}
|
|
|
|
e.preventDefault();
|
|
inputRef.current?.focus();
|
|
};
|
|
|
|
window.addEventListener("keydown", onKeyDown);
|
|
return () => window.removeEventListener("keydown", onKeyDown);
|
|
}, []);
|
|
|
|
return <Input {...props} ref={inputRef} />;
|
|
};
|