fix(modals): prompt dialog not selecting (closes #7289)

This commit is contained in:
Elian Doran 2025-10-12 19:04:50 +03:00
parent f185eb1f5a
commit dcb086d203
No known key found for this signature in database

View File

@ -26,7 +26,7 @@ export interface PromptDialogOptions {
readOnly?: boolean; readOnly?: boolean;
} }
export default function PromptDialog() { export default function PromptDialog() {
const modalRef = useRef<HTMLDivElement>(null); const modalRef = useRef<HTMLDivElement>(null);
const formRef = useRef<HTMLFormElement>(null); const formRef = useRef<HTMLFormElement>(null);
const labelRef = useRef<HTMLLabelElement>(null); const labelRef = useRef<HTMLLabelElement>(null);
@ -35,7 +35,7 @@ export default function PromptDialog() {
const [ value, setValue ] = useState(""); const [ value, setValue ] = useState("");
const [ shown, setShown ] = useState(false); const [ shown, setShown ] = useState(false);
const submitValue = useRef<string>(null); const submitValue = useRef<string>(null);
useTriliumEvent("showPromptDialog", (newOpts) => { useTriliumEvent("showPromptDialog", (newOpts) => {
opts.current = newOpts; opts.current = newOpts;
setValue(newOpts.defaultValue ?? ""); setValue(newOpts.defaultValue ?? "");
@ -48,7 +48,7 @@ export default function PromptDialog() {
title={opts.current?.title ?? t("prompt.title")} title={opts.current?.title ?? t("prompt.title")}
size="lg" size="lg"
zIndex={2000} zIndex={2000}
modalRef={modalRef} formRef={formRef} modalRef={modalRef} formRef={formRef}
onShown={() => { onShown={() => {
opts.current?.shown?.({ opts.current?.shown?.({
$dialog: refToJQuerySelector(modalRef), $dialog: refToJQuerySelector(modalRef),
@ -57,6 +57,7 @@ export default function PromptDialog() {
$form: refToJQuerySelector(formRef) $form: refToJQuerySelector(formRef)
}); });
answerRef.current?.focus(); answerRef.current?.focus();
answerRef.current?.select();
}} }}
onSubmit={() => { onSubmit={() => {
submitValue.current = value; submitValue.current = value;