diff --git a/src/client/components/Chat.tsx b/src/client/components/Chat.tsx index ab368d8..419b259 100644 --- a/src/client/components/Chat.tsx +++ b/src/client/components/Chat.tsx @@ -29,6 +29,7 @@ export interface ChatProps { export default class Chat extends React.PureComponent { chatHistoryRef = React.createRef() + inputRef = React.createRef() scrollToBottom = () => { const chatHistoryRef = this.chatHistoryRef.current! @@ -36,9 +37,16 @@ export default class Chat extends React.PureComponent { } componentDidMount () { this.scrollToBottom() + this.focus() } componentDidUpdate () { this.scrollToBottom() + this.focus() + } + focus() { + if (this.props.visible) { + this.inputRef.current?.textArea.current?.focus() + } } render () { const { messages, sendMessage } = this.props @@ -103,7 +111,7 @@ export default class Chat extends React.PureComponent { - + ) }