Changeset View
Changeset View
Standalone View
Standalone View
web/chat/chat-input-text-area.react.js
// @flow | // @flow | ||||
import invariant from 'invariant'; | import invariant from 'invariant'; | ||||
import * as React from 'react'; | import * as React from 'react'; | ||||
import css from './chat-input-bar.css'; | import css from './chat-input-bar.css'; | ||||
type Props = { | type Props = { | ||||
+send?: () => mixed, | +send?: () => mixed, | ||||
+escape?: () => void, | +escape?: () => void, | ||||
+focus: boolean, | +focus: boolean, | ||||
+currentText: string, | +currentText: string, | ||||
+setCurrentText: (text: string) => void, | |||||
}; | }; | ||||
const ChatInputTextArea: React.ComponentType<Props> = React.memo<Props>( | const ChatInputTextArea: React.ComponentType<Props> = React.memo<Props>( | ||||
function ChatInputTextArea(props: Props) { | function ChatInputTextArea(props: Props) { | ||||
const { currentText, focus, escape, send } = props; | const { currentText, focus, escape, send, setCurrentText } = props; | ||||
const textareaRef = React.useRef(null); | const textareaRef = React.useRef(null); | ||||
const focusAndUpdateText = React.useCallback(() => { | const focusAndUpdateText = React.useCallback(() => { | ||||
if (!focus) { | if (!focus) { | ||||
return; | return; | ||||
} | } | ||||
// We need to call focus() first on Safari, otherwise the cursor | // We need to call focus() first on Safari, otherwise the cursor | ||||
Show All 40 Lines | const onKeyDown = (event: SyntheticKeyboardEvent<HTMLTextAreaElement>) => { | ||||
event.preventDefault(); | event.preventDefault(); | ||||
if (!send) { | if (!send) { | ||||
return; | return; | ||||
} | } | ||||
send(); | send(); | ||||
} | } | ||||
}; | }; | ||||
const onChangeMessageText = () => { | const onChangeMessageText = ( | ||||
event: SyntheticEvent<HTMLTextAreaElement>, | |||||
) => { | |||||
setCurrentText(event.currentTarget.value); | |||||
updateHeight(); | updateHeight(); | ||||
}; | }; | ||||
return ( | return ( | ||||
<div className={css.inputBarTextInput}> | <div className={css.inputBarTextInput}> | ||||
<textarea | <textarea | ||||
rows="1" | rows="1" | ||||
placeholder="Type your message" | placeholder="Type your message" | ||||
Show All 12 Lines |