overleaf/services/web/frontend/js/features/chat/components/message-input.tsx
ilkin-overleaf 6c7ee8f778 Merge pull request #20715 from overleaf/ii-bs5-chat-pane
[web] BS5 chat pane

GitOrigin-RevId: 8587aca1372b4d2087863d492e702f04a31c23e2
2024-10-14 11:07:26 +00:00

46 lines
1.3 KiB
TypeScript

import { useTranslation } from 'react-i18next'
import { bsVersion } from '@/features/utils/bootstrap-5'
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={bsVersion({ bs3: 'sr-only', bs5: 'visually-hidden' })}
>
{t('your_message_to_collaborators')}
</label>
<textarea
id="chat-input"
placeholder={`${t('your_message_to_collaborators')}`}
onKeyDown={handleKeyDown}
onClick={resetUnreadMessages}
/>
</form>
)
}
export default MessageInput