diff --git a/src/components/BooleanEditor/BooleanEditor.react.js b/src/components/BooleanEditor/BooleanEditor.react.js index b68316f7ad..38606d2286 100644 --- a/src/components/BooleanEditor/BooleanEditor.react.js +++ b/src/components/BooleanEditor/BooleanEditor.react.js @@ -20,6 +20,7 @@ export default class BooleanEditor extends React.Component { this.checkExternalClick = this.checkExternalClick.bind(this); this.handleKey = this.handleKey.bind(this); + this.inputRef = React.createRef(); } componentDidMount() { @@ -33,7 +34,7 @@ export default class BooleanEditor extends React.Component { } checkExternalClick(e) { - if (!hasAncestor(e.target, this.refs.input)) { + if (!hasAncestor(e.target, this.inputRef.current)) { this.props.onCommit(this.state.value); } } @@ -46,7 +47,7 @@ export default class BooleanEditor extends React.Component { render() { return ( -
+
+
{this.props.categories.map((c) => { let id = c.id || c.name; let count = c.count; diff --git a/src/components/CodeSnippet/CodeSnippet.react.js b/src/components/CodeSnippet/CodeSnippet.react.js index 605d13058e..85b57bbe89 100644 --- a/src/components/CodeSnippet/CodeSnippet.react.js +++ b/src/components/CodeSnippet/CodeSnippet.react.js @@ -13,6 +13,11 @@ import './CodeSnippet.css'; import 'prismjs/plugins/line-numbers/prism-line-numbers'; export default class CodeSnippet extends React.Component { + constructor() { + super(); + this.codeRef = React.createRef(); + } + componentDidMount() { this._highlight(); } @@ -22,7 +27,7 @@ export default class CodeSnippet extends React.Component { } _highlight() { - Prism.highlightElement(this.refs.code); + Prism.highlightElement(this.codeRef.current); } render() { @@ -34,7 +39,7 @@ export default class CodeSnippet extends React.Component { let pageStyle = fullPage ? { minHeight: 'calc(100vh - 96px)'} : {}; return (
-        {this.props.source}
+        {this.props.source}
       
); } diff --git a/src/components/DateTimeEditor/DateTimeEditor.react.js b/src/components/DateTimeEditor/DateTimeEditor.react.js index 79ad194a22..f2af5dc61c 100644 --- a/src/components/DateTimeEditor/DateTimeEditor.react.js +++ b/src/components/DateTimeEditor/DateTimeEditor.react.js @@ -23,6 +23,8 @@ export default class DateTimeEditor extends React.Component { this.checkExternalClick = this.checkExternalClick.bind(this); this.handleKey = this.handleKey.bind(this); + this.inputRef = React.createRef(); + this.editorRef = React.createRef(); } componentWillReceiveProps(props) { @@ -31,16 +33,16 @@ export default class DateTimeEditor extends React.Component { componentDidMount() { document.body.addEventListener('click', this.checkExternalClick); - this.refs.input.addEventListener('keypress', this.handleKey); + this.inputRef.current.addEventListener('keypress', this.handleKey); } componentWillUnmount() { document.body.removeEventListener('click', this.checkExternalClick); - this.refs.input.removeEventListener('keypress', this.handleKey); + this.inputRef.current.removeEventListener('keypress', this.handleKey); } checkExternalClick(e) { - if (!hasAncestor(e.target, this.refs.editor)) { + if (!hasAncestor(e.target, this.editorRef.current)) { this.props.onCommit(this.state.value); } } @@ -100,11 +102,11 @@ export default class DateTimeEditor extends React.Component { } return ( -
+
e.target.select()} onClick={this.toggle.bind(this)} diff --git a/src/components/FileEditor/FileEditor.react.js b/src/components/FileEditor/FileEditor.react.js index 7e438a995a..5c2b507026 100644 --- a/src/components/FileEditor/FileEditor.react.js +++ b/src/components/FileEditor/FileEditor.react.js @@ -21,6 +21,8 @@ export default class FileEditor extends React.Component { this.checkExternalClick = this.checkExternalClick.bind(this); this.handleKey = this.handleKey.bind(this); this.removeFile = this.removeFile.bind(this); + this.inputRef = React.createRef(); + this.fileInputRef = React.createRef(); } componentDidMount() { @@ -31,7 +33,7 @@ export default class FileEditor extends React.Component { fileInputElement.click(); } } - + componentWillUnmount() { document.body.removeEventListener('click', this.checkExternalClick); document.body.removeEventListener('keypress', this.handleKey); @@ -39,7 +41,7 @@ export default class FileEditor extends React.Component { checkExternalClick(e) { const { onCancel } = this.props; - if (!hasAncestor(e.target, this.refs.input) && onCancel) { + if (!hasAncestor(e.target, this.inputRef.current) && onCancel) { onCancel(); } } @@ -61,7 +63,7 @@ export default class FileEditor extends React.Component { } removeFile() { - this.refs.fileInput.value = ''; + this.fileInputRef.current.value = ''; this.props.onCommit(undefined); } @@ -76,9 +78,9 @@ export default class FileEditor extends React.Component { render() { const file = this.props.value; return ( -
+ diff --git a/src/components/GeoPointEditor/GeoPointEditor.react.js b/src/components/GeoPointEditor/GeoPointEditor.react.js index a91c708cb5..597bc529ee 100644 --- a/src/components/GeoPointEditor/GeoPointEditor.react.js +++ b/src/components/GeoPointEditor/GeoPointEditor.react.js @@ -22,15 +22,18 @@ export default class GeoPointEditor extends React.Component { this.checkExternalClick = this.checkExternalClick.bind(this); this.handleKeyLatitude = this.handleKeyLatitude.bind(this); this.handleKeyLongitude = this.handleKeyLongitude.bind(this); + + this.latitudeRef = React.createRef(); + this.longitudeRef = React.createRef(); } componentDidMount() { if (!this.props.disableAutoFocus) { - this.refs.latitude.focus(); + this.latitudeRef.current.focus(); } - this.refs.latitude.setSelectionRange(0, String(this.state.latitude).length); - this.refs.latitude.addEventListener('keypress', this.handleKeyLatitude); - this.refs.longitude.addEventListener('keypress', this.handleKeyLongitude); + this.latitudeRef.current.setSelectionRange(0, String(this.state.latitude).length); + this.latitudeRef.current.addEventListener('keypress', this.handleKeyLatitude); + this.longitudeRef.current.addEventListener('keypress', this.handleKeyLongitude); } componentWillReceiveProps(props) { @@ -45,8 +48,8 @@ export default class GeoPointEditor extends React.Component { } componentWillUnmount() { - this.refs.latitude.removeEventListener('keypress', this.handleKeyLatitude); - this.refs.longitude.removeEventListener('keypress', this.handleKeyLongitude); + this.latitudeRef.current.removeEventListener('keypress', this.handleKeyLatitude); + this.longitudeRef.current.removeEventListener('keypress', this.handleKeyLongitude); } checkExternalClick() { @@ -55,8 +58,8 @@ export default class GeoPointEditor extends React.Component { // check if activeElement is something else from input fields, // to avoid commiting new value on every switch of focus beetween latitude and longitude fields if ( - document.activeElement !== this.refs.latitude && - document.activeElement !== this.refs.longitude + document.activeElement !== this.latitudeRef.current && + document.activeElement !== this.longitudeRef.current ) { this.commitValue(); } @@ -65,8 +68,8 @@ export default class GeoPointEditor extends React.Component { handleKeyLatitude(e) { if (e.keyCode === 13 || e.keyCode === 44) { - this.refs.longitude.focus(); - this.refs.longitude.setSelectionRange(0, String(this.state.longitude).length); + this.longitudeRef.current.focus(); + this.longitudeRef.current.setSelectionRange(0, String(this.state.longitude).length); } } @@ -112,15 +115,15 @@ export default class GeoPointEditor extends React.Component { if (values[1].length <= 0 || !validateNumeric(values[1])) { this.setState({ latitude: values[0] }); - this.refs.longitude.focus(); - this.refs.longitude.setSelectionRange(0, String(this.state.longitude).length); + this.longitudeRef.current.focus(); + this.longitudeRef.current.setSelectionRange(0, String(this.state.longitude).length); return; } if (validateNumeric(values[1])) { this.setState({ latitude: values[0] }); this.setState({ longitude: values[1] }); - this.refs.longitude.focus(); + this.longitudeRef.current.focus(); return; } } @@ -130,14 +133,14 @@ export default class GeoPointEditor extends React.Component { this.setState({ [target]: validateNumeric(value) ? value : this.state[target] }); }; return ( -
+
diff --git a/src/components/Loader/Loader.react.js b/src/components/Loader/Loader.react.js index 9159838ddd..277972f68f 100644 --- a/src/components/Loader/Loader.react.js +++ b/src/components/Loader/Loader.react.js @@ -52,6 +52,13 @@ function getPosition(t) { } export default class Loader extends React.Component { + constructor() { + super(); + this.dot0Ref = React.createRef(); + this.dot1Ref = React.createRef(); + this.dot2Ref = React.createRef(); + } + componentDidMount() { this.mounted = true; this.mountTime = new Date().getTime(); @@ -69,21 +76,21 @@ export default class Loader extends React.Component { let delta = new Date() - this.mountTime; let t = (delta / DURATION) % 1; let pos = getPosition(t); - let style = this.refs.dot0.style; + let style = this.dot0Ref.current.style; style.left = pos.x + 'px'; style.top = pos.y + 'px'; style.width = style.height = getRadius(t) + 'px'; t = (delta / DURATION + 0.4) % 1; pos = getPosition(t); - style = this.refs.dot1.style; + style = this.dot1Ref.current.style; style.left = pos.x + 'px'; style.top = pos.y + 'px'; style.width = style.height = getRadius(t) + 'px'; t = (delta / DURATION + 0.8) % 1; pos = getPosition(t); - style = this.refs.dot2.style; + style = this.dot2Ref.current.style; style.left = pos.x + 'px'; style.top = pos.y + 'px'; style.width = style.height = getRadius(t) + 'px'; @@ -98,9 +105,9 @@ export default class Loader extends React.Component { } return (
-
-
-
+
+
+
); } diff --git a/src/components/LoginForm/LoginForm.react.js b/src/components/LoginForm/LoginForm.react.js index e651658ff1..df824a4b11 100644 --- a/src/components/LoginForm/LoginForm.react.js +++ b/src/components/LoginForm/LoginForm.react.js @@ -13,11 +13,15 @@ import { verticalCenter } from 'stylesheets/base.scss'; // Class-style component, because we need refs export default class LoginForm extends React.Component { + constructor() { + super(); + this.formRef = React.createRef(); + } render() { return (
-
+
{this.props.header}
{this.props.children} @@ -34,7 +38,7 @@ export default class LoginForm extends React.Component { return; } this.props.formSubmit(); - this.refs.form.submit() + this.formRef.current.submit() }} className={styles.submit} value={this.props.action} /> diff --git a/src/components/NumberEditor/NumberEditor.react.js b/src/components/NumberEditor/NumberEditor.react.js index 1f3b579e91..0a63275272 100644 --- a/src/components/NumberEditor/NumberEditor.react.js +++ b/src/components/NumberEditor/NumberEditor.react.js @@ -19,10 +19,11 @@ export default class NumberEditor extends React.Component { this.checkExternalClick = this.checkExternalClick.bind(this); this.handleKey = this.handleKey.bind(this); + this.inputRef = React.createRef(); } componentDidMount() { - this.refs.input.setSelectionRange(0, String(this.state.value).length); + this.inputRef.current.setSelectionRange(0, String(this.state.value).length); document.body.addEventListener('click', this.checkExternalClick); document.body.addEventListener('keypress', this.handleKey); } @@ -33,7 +34,7 @@ export default class NumberEditor extends React.Component { } checkExternalClick(e) { - if (e.target !== this.refs.input) { + if (e.target !== this.inputRef.current) { this.commitValue() } } @@ -64,7 +65,7 @@ export default class NumberEditor extends React.Component { return (
diff --git a/src/components/Range/Range.react.js b/src/components/Range/Range.react.js index ee9b3d3e2a..c1e6b3833f 100644 --- a/src/components/Range/Range.react.js +++ b/src/components/Range/Range.react.js @@ -16,11 +16,12 @@ export default class Range extends React.Component { constructor(props) { super(); this.state = { width: props.width }; + this.metricsRef = React.createRef(); } componentDidMount() { if (!this.props.width) { - this.setState({ width: this.refs.metrics.clientWidth }); + this.setState({ width: this.metricsRef.current.clientWidth }); } } @@ -64,7 +65,7 @@ export default class Range extends React.Component { return (
{tracker} + {content} diff --git a/src/components/StringEditor/StringEditor.react.js b/src/components/StringEditor/StringEditor.react.js index d4859082a3..58ccda18e2 100644 --- a/src/components/StringEditor/StringEditor.react.js +++ b/src/components/StringEditor/StringEditor.react.js @@ -18,10 +18,11 @@ export default class StringEditor extends React.Component { this.checkExternalClick = this.checkExternalClick.bind(this); this.handleKey = this.handleKey.bind(this); + this.inputRef = React.createRef(); } componentDidMount() { - this.refs.input.setSelectionRange(0, this.state.value.length); + this.inputRef.current.setSelectionRange(0, this.state.value.length); document.body.addEventListener('click', this.checkExternalClick); document.body.addEventListener('keypress', this.handleKey); } @@ -32,7 +33,7 @@ export default class StringEditor extends React.Component { } checkExternalClick(e) { - if (e.target !== this.refs.input) { + if (e.target !== this.inputRef.current) { this.props.onCommit(this.state.value); } } @@ -57,7 +58,7 @@ export default class StringEditor extends React.Component { return (