Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix: topic renaming input focus issue in context menu (#11323)

Inneidd065fc9916e
diff --git a/src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/List/Item/Editing.tsx b/src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/List/Item/Editing.tsx
index b521715a5bb..e5c5f63dce2 100644
--- a/src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/List/Item/Editing.tsx
+++ b/src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/List/Item/Editing.tsx
@@ -1,5 +1,6 @@
-import { Input, Popover } from '@lobehub/ui';
-import { memo, useCallback, useState } from 'react';
+import { Input, type InputProps, Popover } from '@lobehub/ui';
+import type { InputRef } from 'antd';
+import { memo, useCallback, useEffect, useRef, useState } from 'react';
import { useChatStore } from '@/store/chat';
@@ -9,6 +10,18 @@ interface EditingProps {
toggleEditing: (visible?: boolean) => void;
}
+function FocusableInput({ ...props }: InputProps) {
+ const ref = useRef<InputRef>(null);
+ useEffect(() => {
+ queueMicrotask(() => {
+ if (ref.current) {
+ ref.current.input?.focus();
+ }
+ });
+ }, []);
+ return <Input {...props} ref={ref} />;
+}
+
const Editing = memo<EditingProps>(({ id, title, toggleEditing }) => {
const [newTitle, setNewTitle] = useState(title);
const [editing, updateTopicTitle] = useChatStore((s) => [
@@ -41,19 +54,14 @@ const Editing = memo<EditingProps>(({ id, title, toggleEditing }) => {
);
}
}
- toggleEditing(false);
}, [newTitle, title, id, updateTopicTitle, toggleEditing]);
return (
<Popover
content={
- <Input
- autoFocus
+ <FocusableInput
defaultValue={title}
- onBlur={() => {
- handleUpdate();
- toggleEditing(false);
- }}
+ onBlur={handleUpdate}
onChange={(e) => setNewTitle(e.target.value)}
onClick={(e) => e.stopPropagation()}
onPressEnter={() => {
@@ -64,6 +72,7 @@ const Editing = memo<EditingProps>(({ id, title, toggleEditing }) => {
}
onOpenChange={(open) => {
if (!open) handleUpdate();
+
toggleEditing(open);
}}
open={editing}