Chat input autofocus

This commit is contained in:
khlieng 2015-02-10 02:39:19 +01:00
parent ed09a97ade
commit 21160be407
2 changed files with 11 additions and 4 deletions

View File

@ -7,7 +7,8 @@ var tabActions = require('../actions/tab');
var MessageInput = React.createClass({ var MessageInput = React.createClass({
mixins: [ mixins: [
Reflux.connect(selectedTabStore, 'selectedTab') Reflux.connect(selectedTabStore, 'selectedTab'),
Reflux.listenTo(tabActions.select, 'tabSelected')
], ],
getInitialState: function() { getInitialState: function() {
@ -16,6 +17,14 @@ var MessageInput = React.createClass({
}; };
}, },
componentDidMount: function() {
this.refs.input.getDOMNode().focus();
},
tabSelected: function() {
this.refs.input.getDOMNode().focus();
},
handleKey: function(e) { handleKey: function(e) {
if (e.which === 13 && e.target.value) { if (e.which === 13 && e.target.value) {
var tab = this.state.selectedTab; var tab = this.state.selectedTab;
@ -32,7 +41,7 @@ var MessageInput = React.createClass({
render: function() { render: function() {
return ( return (
<div className="message-input-wrap"> <div className="message-input-wrap">
<input className="message-input" type="text" onKeyDown={this.handleKey} /> <input ref="input" className="message-input" type="text" onKeyDown={this.handleKey} />
</div> </div>
); );
} }

View File

@ -59,8 +59,6 @@ socket.on('mode', function(data) {
socket.on('whois', function(data) { socket.on('whois', function(data) {
var tab = selectedTabStore.getState(); var tab = selectedTabStore.getState();
console.log(data.channels);
messageActions.inform('Nick: ' + data.nick, tab.server, tab.channel); messageActions.inform('Nick: ' + data.nick, tab.server, tab.channel);
messageActions.inform('Username: ' + data.username, tab.server, tab.channel); messageActions.inform('Username: ' + data.username, tab.server, tab.channel);
messageActions.inform('Realname: ' + data.realname, tab.server, tab.channel); messageActions.inform('Realname: ' + data.realname, tab.server, tab.channel);