mirror of
https://github.com/zadam/trilium.git
synced 2025-11-17 18:50:41 +01:00
feat(collections/board): restore focus
This commit is contained in:
@@ -227,10 +227,12 @@ export function TitleEditor({ currentValue, placeholder, save, dismiss, multilin
|
||||
isNewItem?: boolean;
|
||||
}) {
|
||||
const inputRef = useRef<any>(null);
|
||||
const focusElRef = useRef<Element>(null);
|
||||
const dismissOnNextRefreshRef = useRef(false);
|
||||
const shouldDismiss = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
focusElRef.current = document.activeElement;
|
||||
inputRef.current?.focus();
|
||||
inputRef.current?.select();
|
||||
}, [ inputRef ]);
|
||||
@@ -254,8 +256,11 @@ export function TitleEditor({ currentValue, placeholder, save, dismiss, multilin
|
||||
onKeyDown={(e: TargetedKeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
||||
if (e.key === "Enter" || e.key === "Escape") {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
shouldDismiss.current = (e.key === "Escape");
|
||||
e.currentTarget.blur();
|
||||
if (focusElRef.current instanceof HTMLElement) {
|
||||
focusElRef.current.focus();
|
||||
}
|
||||
}
|
||||
}}
|
||||
onBlur={(newValue) => {
|
||||
|
||||
Reference in New Issue
Block a user