mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
e103f736e1
GitOrigin-RevId: a1b65129e94735f0215ff2eaa9a8a36dd6093176
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
import PropTypes from 'prop-types'
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
function MessageInput({ resetUnreadMessages, sendMessage }) {
|
|
const { t } = useTranslation()
|
|
|
|
function handleKeyDown(event) {
|
|
if (event.key === 'Enter') {
|
|
event.preventDefault()
|
|
sendMessage(event.target.value)
|
|
// wrap the form reset in setTimeout so input sources have time to finish
|
|
// https://github.com/overleaf/internal/pull/9206
|
|
window.setTimeout(() => {
|
|
event.target.blur()
|
|
event.target.closest('form').reset()
|
|
event.target.focus()
|
|
}, 0)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<form className="new-message">
|
|
<label htmlFor="chat-input" className="sr-only">
|
|
{t('your_message')}
|
|
</label>
|
|
<textarea
|
|
id="chat-input"
|
|
placeholder={`${t('your_message')}…`}
|
|
onKeyDown={handleKeyDown}
|
|
onClick={resetUnreadMessages}
|
|
/>
|
|
</form>
|
|
)
|
|
}
|
|
|
|
MessageInput.propTypes = {
|
|
resetUnreadMessages: PropTypes.func.isRequired,
|
|
sendMessage: PropTypes.func.isRequired,
|
|
}
|
|
|
|
export default MessageInput
|