Closed punkpeye closed 1 week ago
Hi @punkpeye, thanks for your question! It looks like there was some confusion about the focus()
method from useInputControl()
. The key thing to note is that input.focus()
simulates the browser's focus and focusin events, but it does not actually move the focus to the input element itself.
If you want to programmatically move the focus to an input field, you'll need to use the native DOM method, like inputElement.focus()
, e.g.
function Example() {
const textareaRef = useRef();
useEffect(() => {
if (!chatSession.focused) {
return;
}
textareaRef.current.focus();
}, [chatSession.focused, messageInputControl]);
return (
<textarea
className={css({
_focus: {
border: '1px solid #00d992',
boxShadow: 'none',
},
})}
{...getTextareaProps(fields.message)}
ref={textareaRef}
/>
);
};
I've also created a PR to improve the documentation based on this, so feel free to take a look and let me know if it's still confusing or if you have more suggestions. I appreciate the feedback!
Let me know if that clears things up or if you have more questions!
This makes sense. Documentation improvements definitely help.
Describe the bug and the expected behavior
I am trying to focus a textarea input using
focus()
, but it does not do anything.Conform version
v1.2.2
Steps to Reproduce the Bug or Issue
What browsers are you seeing the problem on?
No response
Screenshots or Videos
No response
Additional context
I am seeing the "this fires" event logged, but textarea is never focused.