@@ -7,6 +7,7 @@ import Editor from './components/Editor'
77 * - value? -- input value
88 * - onChange? -- function called when input value change
99 * - json? -- json to edit
10+ * - editorPosition? -- {x,y} overrides the position of the editor
1011*/
1112export default class extends Component {
1213
@@ -46,8 +47,12 @@ export default class extends Component {
4647 }
4748
4849 updateEditorPosition ( ) {
49- const inputBoundRect = this . inputRef . current . getBoundingClientRect ( ) ;
50- this . setState ( { editorPosition : { x :inputBoundRect . left , y : inputBoundRect . top + inputBoundRect . height } } ) ;
50+ if ( this . props . editorPosition ) {
51+ this . setState ( { editorPosition : this . props . editorPosition } ) ;
52+ } else if ( this . inputRef && this . inputRef . current ) {
53+ const inputBoundRect = this . inputRef . current . getBoundingClientRect ( ) ;
54+ this . setState ( { editorPosition : { x :inputBoundRect . left , y : inputBoundRect . top + inputBoundRect . height } } ) ;
55+ }
5156 }
5257
5358 componentWillReceiveProps ( newProps ) {
@@ -95,7 +100,7 @@ export default class extends Component {
95100 render ( ) {
96101 const { inputProps, json} = this . props ;
97102 const { value, editorOpened, editorPosition} = this . state ;
98- return < span >
103+ return < React . Fragment >
99104 < input ref = { this . inputRef } type = 'text' value = { value } onChange = { this . onChange } onFocus = { this . onFocus } onBlur = { this . onBlur } { ...inputProps } />
100105 { editorOpened && < Editor
101106 input = { this . inputRef . current }
@@ -105,6 +110,6 @@ export default class extends Component {
105110 onJsonPathChanged = { this . changePath }
106111 onMouseEnter = { this . disableBlur }
107112 onMouseLeave = { this . onMouseLeaveFromEditor } /> }
108- </ span >
113+ </ React . Fragment >
109114 }
110115}
0 commit comments