From c483940da090d3ded148dfc6c179f6d6d352a768 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Thu, 19 Sep 2019 13:44:02 +0200 Subject: [PATCH] fix: stop Editor competing with Modal for focus Editor now checks if the modal is open before trying to obtain focus. --- client/src/templates/Challenges/classic/Editor.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/client/src/templates/Challenges/classic/Editor.js b/client/src/templates/Challenges/classic/Editor.js index 3d6bd85ea8..c35bf32f08 100644 --- a/client/src/templates/Challenges/classic/Editor.js +++ b/client/src/templates/Challenges/classic/Editor.js @@ -5,12 +5,13 @@ import { connect } from 'react-redux'; import { createSelector } from 'reselect'; import { executeChallenge, updateFile } from '../redux'; -import { userSelector } from '../../../redux'; +import { userSelector, isDonationModalOpenSelector } from '../../../redux'; import { Loader } from '../../../components/helpers'; const MonacoEditor = React.lazy(() => import('react-monaco-editor')); const propTypes = { + canFocus: PropTypes.bool, contents: PropTypes.string, dimensions: PropTypes.object, executeChallenge: PropTypes.func.isRequired, @@ -21,8 +22,12 @@ const propTypes = { }; const mapStateToProps = createSelector( + isDonationModalOpenSelector, userSelector, - ({ theme = 'night' }) => ({ theme }) + (open, { theme = 'night' }) => ({ + canFocus: !open, + theme + }) ); const mapDispatchToProps = dispatch => @@ -104,7 +109,7 @@ class Editor extends Component { editorDidMount = (editor, monaco) => { this._editor = editor; - this._editor.focus(); + if (this.props.canFocus) this._editor.focus(); this._editor.addAction({ id: 'execute-challenge', label: 'Run tests',