🚸(frontend) focus to field on forward

When user forwards a message, the message form should focus the `to`
field not the message composer.
This commit is contained in:
jbpenrath
2026-04-16 11:57:20 +02:00
parent 730fea15ee
commit 1103721b75
2 changed files with 7 additions and 6 deletions

View File

@@ -14,6 +14,7 @@ export type ComboBoxProps = {
onChange?: (value: string[]) => void,
renderChipLabel?: (item: Option) => string,
valueValidator?: (value: string) => boolean,
autoFocus?: boolean,
} & Omit<SelectProps, 'value' | 'defaultValue' | 'onChange'>;
export const ComboBox = (props: ComboBoxProps) => {
@@ -150,6 +151,10 @@ export const ComboBox = (props: ComboBoxProps) => {
props.onChange?.(selectedItems.map(item => item.value || item.label));
}, [selectedItems]);
useEffect(() => {
if (props.autoFocus) inputRef.current?.focus();
}, [props.autoFocus]);
return (
<Field className={clsx("c__combobox", {
"c__combobox--disabled": props.disabled,

View File

@@ -535,11 +535,6 @@ export const MessageForm = ({
}
}
useEffect(() => {
if (draftMessage) form.setFocus("subject");
else form.setFocus("to")
}, []);
useEffect(() => {
startAutoSave();
return () => stopAutoSave();
@@ -599,6 +594,7 @@ export const MessageForm = ({
<RhfContactComboBox
name="to"
label={t("To:")}
autoFocus={mode === "forward"}
// icon={<span className="material-icons">group</span>}
text={form.formState.errors.to && !Array.isArray(form.formState.errors.to) ? form.formState.errors.to.message : t("Enter the email addresses of the recipients separated by commas")}
textItems={Array.isArray(form.formState.errors.to) ? form.formState.errors.to?.map((error, index) => t(error!.message as string, { email: form.getValues('to')?.[index] })) : []}
@@ -668,7 +664,7 @@ export const MessageForm = ({
draft={draft}
submitDraft={form.handleSubmit(saveDraft)}
ensureDraft={ensureDraft}
blockNoteOptions={{ autofocus: canWriteMessages ? "end" : undefined }}
blockNoteOptions={{ autofocus: canWriteMessages && mode !== "forward" ? "end" : undefined }}
uploadInlineImage={attachmentHook.uploadInlineImage}
uploadFiles={attachmentHook.uploadFiles}
removeInlineImage={attachmentHook.removeInlineImage}