diff --git a/.size-snapshot.json b/.size-snapshot.json index 7baaabc..1ca4301 100644 --- a/.size-snapshot.json +++ b/.size-snapshot.json @@ -1,25 +1,25 @@ { "dist/index.umd.js": { - "bundled": 15914, - "minified": 6880, - "gzipped": 2594 + "bundled": 15915, + "minified": 6891, + "gzipped": 2591 }, "dist/index.umd.min.js": { - "bundled": 15914, - "minified": 6880, - "gzipped": 2594 + "bundled": 15915, + "minified": 6891, + "gzipped": 2591 }, "dist/index.esm.js": { - "bundled": 14601, - "minified": 7845, - "gzipped": 2641, + "bundled": 14602, + "minified": 7856, + "gzipped": 2636, "treeshaked": { "rollup": { - "code": 6566, + "code": 6577, "import_statements": 63 }, "webpack": { - "code": 7644 + "code": 7655 } } } diff --git a/lib/cjs/react-sane-contenteditable.js b/lib/cjs/react-sane-contenteditable.js index 79df954..895199c 100644 --- a/lib/cjs/react-sane-contenteditable.js +++ b/lib/cjs/react-sane-contenteditable.js @@ -197,7 +197,6 @@ function (_Component) { value: _this.sanitiseValue(props.content, props) }; _this.ref = null; - _this.selection = document.getSelection(); return _this; } @@ -205,6 +204,7 @@ function (_Component) { key: "componentDidMount", value: function componentDidMount() { var focus = this.props.focus; + this.selection = document.getSelection(); if (focus && this.ref) { this.setCaretPosition(); diff --git a/lib/esm/react-sane-contenteditable.js b/lib/esm/react-sane-contenteditable.js index 5e69a85..7f9a809 100644 --- a/lib/esm/react-sane-contenteditable.js +++ b/lib/esm/react-sane-contenteditable.js @@ -164,7 +164,6 @@ function (_Component) { value: _this.sanitiseValue(props.content, props) }; _this.ref = null; - _this.selection = document.getSelection(); return _this; } @@ -172,6 +171,7 @@ function (_Component) { key: "componentDidMount", value: function componentDidMount() { var focus = this.props.focus; + this.selection = document.getSelection(); if (focus && this.ref) { this.setCaretPosition(); diff --git a/src/react-sane-contenteditable.js b/src/react-sane-contenteditable.js index e9fa892..ba37711 100644 --- a/src/react-sane-contenteditable.js +++ b/src/react-sane-contenteditable.js @@ -53,12 +53,13 @@ class ContentEditable extends Component { }; this.ref = null; - this.selection = document.getSelection(); } componentDidMount() { const { focus } = this.props; + this.selection = document.getSelection(); + if (focus && this.ref) { this.setCaretPosition(); this.ref.focus();