diff --git a/src/app/components/user-profile/UserChips.tsx b/src/app/components/user-profile/UserChips.tsx index f2df0207..950474a9 100644 --- a/src/app/components/user-profile/UserChips.tsx +++ b/src/app/components/user-profile/UserChips.tsx @@ -2,6 +2,7 @@ import { KeyboardEventHandler, MouseEventHandler, useCallback, + useEffect, useMemo, useRef, useState, @@ -447,6 +448,8 @@ export function IgnoredUserAlert() { export function OptionsChip({ userId }: { userId: string }) { const mx = useMatrixClient(); const [cords, setCords] = useState(); + const [editingNick, setEditingNick] = useState(false); + const nickInputRef = useRef(null); const open: MouseEventHandler = (evt) => { setCords(evt.currentTarget.getBoundingClientRect()); @@ -471,8 +474,12 @@ export function OptionsChip({ userId }: { userId: string }) { const currentNick = useNickname(userId); const setNickname = useSetNickname(); - const [editingNick, setEditingNick] = useState(false); - const nickInputRef = useRef(null); + + useEffect(() => { + if (editingNick) { + nickInputRef.current?.focus(); + } + }, [editingNick]); const handleSaveNick = () => { const value = nickInputRef.current?.value ?? ''; @@ -513,7 +520,6 @@ export function OptionsChip({ userId }: { userId: string }) { Nickname