Skip to content

Commit f002d36

Browse files
authored
Merge pull request #6167 from ethereum/ai_textboxes_focus
adding focus to textboxes
2 parents 0a87168 + 3c2fd37 commit f002d36

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

libs/remix-ui/app/src/lib/remix-app/components/modals/modal-wrapper.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,17 @@ const ModalWrapper = (props: ModalWrapperProps) => {
171171
}
172172
}, [props])
173173

174+
useEffect(() => {
175+
if (props.modalType === ModalTypes.textarea && ref.current) {
176+
setTimeout(() => {
177+
// make sure rendering is done before focusing
178+
if (ref.current && 'focus' in ref.current) {
179+
(ref.current as HTMLTextAreaElement).focus()
180+
}
181+
}, 300)
182+
}
183+
}, [props.modalType, state])
184+
174185
// reset the message and input if any, so when the modal is shown again it doesn't show the previous value.
175186
const handleHide = () => {
176187
setState((prevState) => {

libs/remix-ui/remix-ai-assistant/src/components/prompt.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface PromptAreaProps {
2929
modelBtnRef: React.RefObject<HTMLButtonElement>
3030
aiContextGroupList: groupListType[]
3131
aiAssistantGroupList: groupListType[]
32+
textareaRef?: React.RefObject<HTMLTextAreaElement>
3233
}
3334

3435
const _paq = (window._paq = window._paq || [])
@@ -55,7 +56,8 @@ export const PromptArea: React.FC<PromptAreaProps> = ({
5556
contextBtnRef,
5657
modelBtnRef,
5758
aiContextGroupList,
58-
aiAssistantGroupList
59+
aiAssistantGroupList,
60+
textareaRef
5961
}) => {
6062

6163
return (
@@ -110,6 +112,7 @@ export const PromptArea: React.FC<PromptAreaProps> = ({
110112
</div>
111113
<div className="ai-chat-input d-flex flex-column">
112114
<textarea
115+
ref={textareaRef}
113116
style={{ flexGrow: 1 }}
114117
rows={2}
115118
className="form-control bg-light"

libs/remix-ui/remix-ai-assistant/src/components/remix-ui-remix-ai-assistant.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export const RemixUiRemixAiAssistant = React.forwardRef<
5151
const historyRef = useRef<HTMLDivElement | null>(null)
5252
const modelBtnRef = useRef(null)
5353
const contextBtnRef = useRef(null)
54+
const textareaRef = useRef<HTMLTextAreaElement>(null)
5455

5556
useOnClickOutside([modelBtnRef, contextBtnRef], () => setShowAssistantOptions(false))
5657
useOnClickOutside([modelBtnRef, contextBtnRef], () => setShowContextOptions(false))
@@ -200,6 +201,19 @@ export const RemixUiRemixAiAssistant = React.forwardRef<
200201
}
201202
}, [messages])
202203

204+
useEffect(() => {
205+
if (textareaRef.current) {
206+
textareaRef.current.focus()
207+
}
208+
}, [])
209+
210+
useEffect(() => {
211+
// Focus textarea when streaming stops (after request processing)
212+
if (!isStreaming && textareaRef.current) {
213+
textareaRef.current.focus()
214+
}
215+
}, [isStreaming])
216+
203217
// helper to toggle like / dislike feedback and push Matomo events
204218
const recordFeedback = (msgId: string, next: 'like' | 'dislike' | 'none') => {
205219
setMessages(prev =>
@@ -513,6 +527,7 @@ export const RemixUiRemixAiAssistant = React.forwardRef<
513527
modelBtnRef={modelBtnRef}
514528
aiContextGroupList={aiContextGroupList}
515529
aiAssistantGroupList={aiAssistantGroupList}
530+
textareaRef={textareaRef}
516531
/>
517532
</section>
518533
</div>

0 commit comments

Comments
 (0)