({ handleReturn, queryInfo }: Props)
| 39 | } |
| 40 | |
| 41 | const TextInput = ({ handleReturn, queryInfo }: Props) => { |
| 42 | const [editorState, setEditorState] = useState(stateFor(queryInfo)) |
| 43 | const [mentionListOpen, setMentionListOpen] = useState(false) |
| 44 | const [hasFocus, setHasFocus] = useState(false) |
| 45 | const editor = useRef(null) |
| 46 | |
| 47 | const wrappedHandleReturn = useCallback((event: KeyboardEvent, nextEditorState: EditorState) => { |
| 48 | if (!mentionListOpen) { |
| 49 | handleReturn(event, nextEditorState) |
| 50 | return 'handled' |
| 51 | } |
| 52 | return 'not-handled' |
| 53 | }, [mentionListOpen]) |
| 54 | |
| 55 | const onFocus = useCallback(() => setHasFocus(true), [setHasFocus]) |
| 56 | const onBlur = useCallback(() => setHasFocus(false), [setHasFocus]) |
| 57 | const focus = hasFocus ? 'focus' : '' |
| 58 | |
| 59 | return ( |
| 60 | <div className={`textInputTextInput form-control ${focus}`}> |
| 61 | <Editor |
| 62 | ref={editor} |
| 63 | editorState={editorState} |
| 64 | handleReturn={wrappedHandleReturn} |
| 65 | onBlur={onBlur} |
| 66 | onChange={setEditorState} |
| 67 | onFocus={onFocus} |
| 68 | placeholder="Search" |
| 69 | plugins={plugins} |
| 70 | stripPastedStyles |
| 71 | /> |
| 72 | <TopicSuggestions |
| 73 | Suggestions={MentionSuggestions} |
| 74 | setMentionListOpen={setMentionListOpen} |
| 75 | isOpen={mentionListOpen} |
| 76 | /> |
| 77 | </div> |
| 78 | ) |
| 79 | } |
| 80 | |
| 81 | export default TextInput |
nothing calls this directly
no test coverage detected