Skip to content

Commit c3414c7

Browse files
(feature) add editorPosition override property and set component wrapper to a fragment
1 parent 4b9b381 commit c3414c7

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class App extends Component {
4040
| value | `string` | `false` | input default value |
4141
| json | `object` | `false` | json to test the json path and provide autocompletion |
4242
| onChange | `function` | `false` | callback called when jsonPath changed |
43+
| editorPosition| `object` | `false` | {x,y} overrides the position of the editor |
4344

4445
[build-badge]: https://img.shields.io/travis/JeanBaptisteWATENBERG/react-jsonpath-editor/master.png?style=flat-square
4546
[build]: https://travis-ci.org/JeanBaptisteWATENBERG/react-jsonpath-editor

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-jsonpath-editor",
3-
"version": "1.0.1",
3+
"version": "1.1.0-beta",
44
"description": "react-jsonpath-editor React component",
55
"main": "lib/index.js",
66
"module": "es/index.js",

src/index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
1112
export 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

Comments
 (0)