From f200327ef21ff494de737553ca4ded1bd4e4fad7 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 2 Sep 2019 15:59:17 +0200 Subject: [PATCH] show/hide legend when focusing/blurring --- .../views/rooms/BasicMessageComposer.js | 10 ++++++-- .../views/rooms/SendMessageComposer.js | 23 ++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/components/views/rooms/BasicMessageComposer.js b/src/components/views/rooms/BasicMessageComposer.js index d55e9acc86..ef6fda6595 100644 --- a/src/components/views/rooms/BasicMessageComposer.js +++ b/src/components/views/rooms/BasicMessageComposer.js @@ -222,15 +222,21 @@ export default class BasicMessageEditor extends React.Component { return this.getCaret().offset === this._lastTextLength; } - _onBlur = () => { + _onBlur = (event) => { document.removeEventListener("selectionchange", this._onSelectionChange); + if (this.props.onBlur) { + this.props.onBlur(event); + } } - _onFocus = () => { + _onFocus = (event) => { document.addEventListener("selectionchange", this._onSelectionChange); // force to recalculate this._lastSelection = null; this._refreshLastCaretIfNeeded(); + if (this.props.onFocus) { + this.props.onFocus(event); + } } _onSelectionChange = () => { diff --git a/src/components/views/rooms/SendMessageComposer.js b/src/components/views/rooms/SendMessageComposer.js index 65e6673124..8772bf3b66 100644 --- a/src/components/views/rooms/SendMessageComposer.js +++ b/src/components/views/rooms/SendMessageComposer.js @@ -33,6 +33,7 @@ import sdk from '../../../index'; import Modal from '../../../Modal'; import { _t } from '../../../languageHandler'; import ContentMessages from '../../../ContentMessages'; +import classNames from "classnames"; function addReplyToMessageContent(content, repliedToEvent, permalinkCreator) { const replyContent = ReplyThread.makeReplyMixIn(repliedToEvent); @@ -87,6 +88,7 @@ export default class SendMessageComposer extends React.Component { constructor(props, context) { super(props, context); + this.state = {}; this.model = null; this._editorRef = null; this.currentlyComposedEditorState = null; @@ -329,7 +331,18 @@ export default class SendMessageComposer extends React.Component { } } + _onFocus = () => { + this.setState({focused: true}); + } + + _onBlur = () => { + this.setState({focused: false}); + } + render() { + const legendClasses = classNames("mx_SendMessageComposer_legend", { + "mx_SendMessageComposer_legend_shown": this.state.focused, + }); return (
@@ -342,8 +355,16 @@ export default class SendMessageComposer extends React.Component { label={this.props.placeholder} placeholder={this.props.placeholder} onChange={this._saveStoredEditorState} + onFocus={this._onFocus} + onBlur={this._onBlur} /> -
**bold**_italic_~strikethrough~`code`> quote
+
+ **bold** + _italic_ + <del>strikethrough</del> + `code` + > quote +
); }