mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-24 21:12:38 -04:00
c597444179
GitOrigin-RevId: d45d155277a7fc4fbd137f8c640e4a22b1b82399
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { useTranslation } from 'react-i18next'
|
|
|
|
type MessageInputProps = {
|
|
resetUnreadMessages: () => void
|
|
sendMessage: (message: string) => void
|
|
}
|
|
|
|
function MessageInput({ resetUnreadMessages, sendMessage }: MessageInputProps) {
|
|
const { t } = useTranslation()
|
|
|
|
function handleKeyDown(event: React.KeyboardEvent) {
|
|
const selectingCharacter = event.nativeEvent.isComposing
|
|
if (event.key === 'Enter' && !selectingCharacter) {
|
|
event.preventDefault()
|
|
const target = event.target as HTMLInputElement
|
|
sendMessage(target.value)
|
|
// wrap the form reset in setTimeout so input sources have time to finish
|
|
// https://github.com/overleaf/internal/pull/9206
|
|
window.setTimeout(() => {
|
|
target.blur()
|
|
target.closest('form')?.reset()
|
|
target.focus()
|
|
}, 0)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<form className="new-message">
|
|
<label htmlFor="chat-input" className="sr-only">
|
|
{t('your_message_to_collaborators')}
|
|
</label>
|
|
<textarea
|
|
id="chat-input"
|
|
placeholder={`${t('your_message_to_collaborators')}…`}
|
|
onKeyDown={handleKeyDown}
|
|
onClick={resetUnreadMessages}
|
|
/>
|
|
</form>
|
|
)
|
|
}
|
|
|
|
export default MessageInput
|