bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/chat/message-form/component.jsx

96 lines
2.4 KiB
React
Raw Normal View History

2016-06-02 00:33:19 +08:00
import React, { Component, PropTypes } from 'react';
import { findDOMNode } from 'react-dom';
import cx from 'classnames';
import styles from './styles';
import Button from '../../button/component';
import TextareaAutosize from 'react-autosize-textarea';
const propTypes = {
};
const defaultProps = {
};
export default class MessageForm extends Component {
constructor(props) {
super(props);
this.state = {
message: '',
};
this.handleMessageChange = this.handleMessageChange.bind(this);
this.handleMessageKeyUp = this.handleMessageKeyUp.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleMessageKeyUp(e) {
if (e.keyCode === 13 && !e.shiftKey) {
this.refs.btnSubmit.click();
// FIX: I dont know why the live bellow dont trigger the handleSubmit function
// this.refs.form.submit();
}
}
handleMessageChange(e) {
this.setState({ message: e.target.value });
}
handleSubmit(e) {
e.preventDefault();
let message = this.state.message.trim();
// Sanitize. See: http://shebang.brandonmintern.com/foolproof-html-escaping-in-javascript/
let div = document.createElement('div');
div.appendChild(document.createTextNode(message));
message = div.innerHTML;
2016-06-02 00:33:19 +08:00
if (!message) {
return;
}
this.setState({ message: '' });
2016-06-03 02:40:27 +08:00
this.props.handleSendMessage(message);
2016-06-02 00:33:19 +08:00
}
render() {
return (
<form
{...this.props}
ref="form"
className={cx(this.props.className, styles.form)}
onSubmit={this.handleSubmit}>
<div className={styles.actions}>
<Button
onClick={() => alert('Not supported yet...')}
icon={'circle-add'}
size={'sm'}
circle={true}
/>
</div>
<TextareaAutosize
className={styles.input}
id="message-input"
maxlength=""
aria-controls={this.props.chatAreaId}
aria-label="Message input for Channel #geral"
autocorrect="off"
autocomplete="off"
spellcheck="true"
value={this.state.message}
onChange={this.handleMessageChange}
onKeyUp={this.handleMessageKeyUp}
/>
<input ref="btnSubmit" className={'sr-only'} type="submit" value="Send Message" />
</form>
);
}
}
MessageForm.propTypes = propTypes;
MessageForm.defaultProps = defaultProps;