From 48391620c11d10ab634ecd97254c847705b2c724 Mon Sep 17 00:00:00 2001 From: Joey Payne Date: Tue, 17 May 2016 07:26:37 -0600 Subject: [PATCH] Fix notebook text field not focusing properly --- app/components/LibraryNav.jsx | 35 ++- app/components/TextField.jsx | 575 ++++++++++++++++++++++++++++++++++ app/containers/App.jsx | 1 + app/store/configureStore.jsx | 9 +- package.json | 1 + 5 files changed, 607 insertions(+), 14 deletions(-) create mode 100644 app/components/TextField.jsx diff --git a/app/components/LibraryNav.jsx b/app/components/LibraryNav.jsx index e45c41e..37d86db 100644 --- a/app/components/LibraryNav.jsx +++ b/app/components/LibraryNav.jsx @@ -15,6 +15,7 @@ import Edit from 'material-ui/lib/svg-icons/editor/mode-edit' import Delete from 'material-ui/lib/svg-icons/action/delete' import Divider from 'material-ui/lib/divider' import SelectableList from 'SelectableList' +import TextField from 'TextField' import uuid from 'node-uuid' import path from 'path-extra' @@ -34,7 +35,6 @@ const { IconButton, MenuItem, Badge, - TextField, Styles, Paper } = mui @@ -216,25 +216,35 @@ export default class LibraryNav extends React.Component { }; - menuItemClicked = (i, ev) => { + menuItemClicked = (i, ev, callback) => { this.refs.notebookList.setIndex(-1) var item = this.props.navigation.menuItems[i] var type = 'leftClick' var nativeEvent = ev.nativeEvent - if(nativeEvent.button == 2){ - //Right click - type = 'rightClick' + if(nativeEvent){ + if(nativeEvent.button == 2){ + //Right click + type = 'rightClick' + } } if (item.isNotebook){ var notebook = utils.loadNotebookByName(item.name) notebook = utils.updateObject(item, notebook) - this.props.updateSelection(notebook) + this.props.updateSelection(notebook, () => { + if(utils.isFunction(callback)){ + callback(i, item, type, ev) + } + }) } else if(item.glob){ - this.props.updateSelection(item) + this.props.updateSelection(item, () => { + if(utils.isFunction(callback)){ + callback(i, item, type, ev) + } + }) } // Process any callbacks attached to the menu @@ -248,9 +258,7 @@ export default class LibraryNav extends React.Component { renameTapped = (i) => { var nbs = this.props.navigation.notebooks nbs[i].state = 'editing' - this.props.updateNotebook(nbs[i], i, () => { - this.refs['textField'+i].focus() - }) + this.props.updateNotebook(nbs[i], i) this.props.closeContextMenu() } @@ -317,7 +325,6 @@ export default class LibraryNav extends React.Component { this.props.updateSelection(this.props.navigation.notebooks[i]) } this.refs.mainList.setIndex(-1) - }; preventEventProp = (ev) => { @@ -329,6 +336,11 @@ export default class LibraryNav extends React.Component { {this.props.navigation.notebooks.map((notebook, i) =>{ var l = null + var selIndex = this.props.navigation.selectionIndex + var focus = false + if (selIndex == i){ + focus = true + } if (notebook.state == 'editing'){ l = {this.state.errorText} + ) : null; + + let floatingLabelTextElement = floatingLabelText ? ( + + {floatingLabelText} + + ) : null; + + let inputProps; + let inputElement; + + inputProps = { + id: inputId, + ref: 'input', + onBlur: this._handleInputBlur, + onFocus: this._handleInputFocus, + focus: this.props.focus, + disabled: this.props.disabled, + onKeyDown: this._handleInputKeyDown, + }; + const inputStyle = this.mergeStyles(styles.input, this.props.inputStyle); + + if (!this.props.hasOwnProperty('valueLink')) { + inputProps.onChange = this._handleInputChange; + } + + if (this.props.children) { + inputElement = React.cloneElement(this.props.children, + { + ...inputProps, + ...this.props.children.props, + style: this.mergeStyles(inputStyle, this.props.children.props.style), + }); + } else { + inputElement = multiLine ? ( + + ) : ( + this.state.isFocused ? ( + ) : ( + ) + + ); + } + + return ( +
+ {floatingLabelTextElement} + {hintText ? + : + null + } + {inputElement} + {underlineShow ? + : + null + } + {errorTextElement} +
+ ); + }, + +}); + +export default TextField; + diff --git a/app/containers/App.jsx b/app/containers/App.jsx index b7d49d3..11ce0e7 100644 --- a/app/containers/App.jsx +++ b/app/containers/App.jsx @@ -86,6 +86,7 @@ class App extends React.Component { />