Closed chloe-schoreisz closed 2 years ago
Hi @chloe-schoreisz, thank you for your question.
The focus can be set using the focus() method provided by the <MessageInput /> component.
e.g.
const inputRef = useRef();
const [disabled, setDisabled] = useState(false);
const sendMessage = () => {
setDisabled(true);
senToWire().then( () => {
inputRef.current.focus();
setDisabled(false);
});
<MessageInput ref={inputRef} onSend={sendMessage} disabled={disabled} />
Thanks for the solution ! Would this be considered a common use case ? I wonder if it this behaviour should be native to the component.
What other common use cases for the disable
props do you have ?
@chloe-schoreisz I'm not sure if it is a common use case. Why do you want disable the input, when a message is sending? If you do it, the user will not be able to write the next message untill the previous one is sent.
What exactly behavior do you consider native, disabling while sending or refocus after sent?
BTW, sorry I forgot about one property activateAfterChange it's meant for a different use case, but you can try setting it to true to automagically set the focus after sending.
Other common use cases for the disabled prop are for example when you have no active user selected, or when connection to server has not been established. Depending on the application, you may also want to block messages from being sent to the user when they are not connected.
I set the
disabled
prop of messages totrue
while sending. This caused the input box to not be refocused once reenabled. Would it be possible to refocus the message once the propdisabled
isfalse
?