Merge pull request #262 from mattermost/fix-focus-of-webview

Fix webview doesn't get focus correctly

Close #231
This commit is contained in:
Yuya Ochiai
2016-09-09 23:52:45 +09:00
committed by GitHub
3 changed files with 15 additions and 6 deletions

View File

@@ -82,10 +82,8 @@ var MainPage = React.createClass({
});
var focusListener = function() {
var webview = document.getElementById('mattermostView' + thisObj.state.key);
webview.focus();
thisObj.handleOnTeamFocused(thisObj.state.key);
thisObj.refs[`mattermostView${thisObj.state.key}`].focusOnWebView();
};
var currentWindow = remote.getCurrentWindow();
@@ -94,14 +92,17 @@ var MainPage = React.createClass({
currentWindow.removeListener('focus', focusListener);
});
},
componentDidUpdate: function() {
this.refs[`mattermostView${this.state.key}`].focusOnWebView();
},
handleSelect: function(key) {
const newKey = (this.props.teams.length + key) % this.props.teams.length;
this.setState({
key: newKey
});
this.handleOnTeamFocused(key);
this.handleOnTeamFocused(newKey);
var webview = document.getElementById('mattermostView' + key);
var webview = document.getElementById('mattermostView' + newKey);
ipcRenderer.send('update-title', {
title: webview.getTitle()
});
@@ -455,6 +456,13 @@ var MattermostView = React.createClass({
webContents.reload();
});
},
focusOnWebView: function() {
const webview = ReactDOM.findDOMNode(this.refs.webview);
if (!webview.getWebContents().isFocused()) {
webview.focus();
webview.getWebContents().focus();
}
},
render: function() {
const errorView = this.state.errorInfo ? (<ErrorView id={ this.props.id + '-fail' } style={ this.props.style } className="errorView" errorInfo={ this.state.errorInfo }></ErrorView>) : null;
// 'disablewebsecurity' is necessary to display external images.