Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ui/src/modules/common/components/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type ErxesEditorProps = {
keyBindingFn?: (e: any) => any;
onUpArrow?: (e: KeyboardEvent) => void;
onDownArrow?: (e: KeyboardEvent) => void;
onEscape?: (e: KeyboardEvent) => void;
handleFileInput?: (e: React.FormEvent<HTMLInputElement>) => void;
placeholder?: string | React.ReactNode;
};
Expand Down Expand Up @@ -128,6 +129,7 @@ export class ErxesEditor extends React.Component<ErxesEditorProps> {
controls,
onUpArrow,
onDownArrow,
onEscape,
bordered,
isTopPopup = false,
plugins
Expand Down Expand Up @@ -172,6 +174,7 @@ export class ErxesEditor extends React.Component<ErxesEditorProps> {
keyBindingFn={this.props.keyBindingFn}
onUpArrow={onUpArrow}
onDownArrow={onDownArrow}
onEscape={onEscape}
ref={element => {
this.editor = element;
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type State = {
collectedMentions: any;
suggestions: any;
templatesState: any;
hideTemplates: boolean;
};

const MentionEntry = props => {
Expand Down Expand Up @@ -91,7 +92,8 @@ export default class Editor extends React.Component<EditorProps, State> {
),
collectedMentions: [],
suggestions: this.props.mentions.toArray(),
templatesState: null
templatesState: null,
hideTemplates: false
};

this.mentionPlugin = createMentionPlugin({
Expand Down Expand Up @@ -126,7 +128,7 @@ export default class Editor extends React.Component<EditorProps, State> {
}

onChange = editorState => {
this.setState({ editorState });
this.setState({ editorState, hideTemplates: false });

this.props.onChange(this.getContent(editorState));

Expand Down Expand Up @@ -235,11 +237,15 @@ export default class Editor extends React.Component<EditorProps, State> {
this.onArrow(e, 1);
};

onEscape = () => {
this.setState({ hideTemplates: true });
}

// Render response templates suggestions
renderTemplates() {
const { templatesState } = this.state;
const { templatesState, hideTemplates } = this.state;

if (!templatesState) {
if (!templatesState || hideTemplates) {
return null;
}

Expand Down Expand Up @@ -312,7 +318,7 @@ export default class Editor extends React.Component<EditorProps, State> {
// handle enter in editor
if (e.key === 'Enter') {
// select response template
if (this.state.templatesState) {
if (this.state.templatesState && !this.state.hideTemplates) {
this.onSelectTemplate();

return null;
Expand Down Expand Up @@ -359,6 +365,7 @@ export default class Editor extends React.Component<EditorProps, State> {
keyBindingFn: this.keyBindingFn,
onUpArrow: this.onUpArrow,
onDownArrow: this.onDownArrow,
onEscape: this.onEscape,
handleFileInput: this.props.handleFileInput,
isTopPopup: true,
plugins,
Expand Down