From bcb0468d5b1ae55d926463e60e873421777fa4ee Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Sun, 10 Mar 2019 23:00:45 +0100 Subject: [PATCH] [docs] Remove unnecessary findDOMNode usage --- docs/src/pages/demos/selects/NativeSelects.js | 7 ++--- docs/src/pages/demos/selects/SimpleSelect.js | 4 +-- .../demos/text-fields/ComposedTextField.js | 29 +++++++++---------- .../demos/text-fields/ComposedTextField.tsx | 28 +++++++++--------- .../material-ui/src/FormLabel/FormLabel.d.ts | 5 ++++ .../src/InputLabel/InputLabel.d.ts | 4 ++- 6 files changed, 40 insertions(+), 37 deletions(-) diff --git a/docs/src/pages/demos/selects/NativeSelects.js b/docs/src/pages/demos/selects/NativeSelects.js index 4e8bc9136b2361..ff09fb50a2bea5 100644 --- a/docs/src/pages/demos/selects/NativeSelects.js +++ b/docs/src/pages/demos/selects/NativeSelects.js @@ -1,5 +1,4 @@ import React from 'react'; -import ReactDOM from 'react-dom'; import { makeStyles } from '@material-ui/core/styles'; import Input from '@material-ui/core/Input'; import OutlinedInput from '@material-ui/core/OutlinedInput'; @@ -31,10 +30,10 @@ function NativeSelects() { name: 'hai', }); - const inputLabelRef = React.useRef(null); + const inputLabel = React.useRef(null); const [labelWidth, setLabelWidth] = React.useState(0); React.useEffect(() => { - setLabelWidth(ReactDOM.findDOMNode(inputLabelRef.current).offsetWidth); + setLabelWidth(inputLabel.current.offsetWidth); }, []); const handleChange = name => event => { @@ -189,7 +188,7 @@ function NativeSelects() { Required - + Age + Name @@ -54,14 +58,14 @@ class ComposedTextField extends React.Component { Name - + Disabled Name @@ -69,24 +73,19 @@ class ComposedTextField extends React.Component { Error - { - this.labelRef = ReactDOM.findDOMNode(ref); - }} - htmlFor="component-outlined" - > + Name Name - + ); diff --git a/docs/src/pages/demos/text-fields/ComposedTextField.tsx b/docs/src/pages/demos/text-fields/ComposedTextField.tsx index 1a7661f16d5fb7..371ef333f447cf 100644 --- a/docs/src/pages/demos/text-fields/ComposedTextField.tsx +++ b/docs/src/pages/demos/text-fields/ComposedTextField.tsx @@ -23,18 +23,20 @@ const styles = (theme: Theme) => export interface Props extends WithStyles {} interface State { + labelWidth: number; name: string; } class ComposedTextField extends React.Component { - labelRef: HTMLElement | null | undefined; + label = React.createRef(); state = { + labelWidth: 0, name: 'Composed TextField', }; componentDidMount() { - this.forceUpdate(); + this.setState({ labelWidth: this.label.current!.offsetWidth }); } handleChange = (event: React.ChangeEvent) => { @@ -42,19 +44,20 @@ class ComposedTextField extends React.Component { }; render() { + const { labelWidth, name } = this.state; const { classes } = this.props; return (
Name - + Name @@ -62,38 +65,33 @@ class ComposedTextField extends React.Component { Name - + Disabled Name Error - { - this.labelRef = ReactDOM.findDOMNode(ref!) as HTMLLabelElement | null; - }} - htmlFor="component-outlined" - > + Name Name - +
); diff --git a/packages/material-ui/src/FormLabel/FormLabel.d.ts b/packages/material-ui/src/FormLabel/FormLabel.d.ts index eb077775734168..d1dca65d280832 100644 --- a/packages/material-ui/src/FormLabel/FormLabel.d.ts +++ b/packages/material-ui/src/FormLabel/FormLabel.d.ts @@ -7,6 +7,11 @@ export interface FormLabelProps extends StandardProps` is used. + */ + ref?: React.Ref; required?: boolean; } diff --git a/packages/material-ui/src/InputLabel/InputLabel.d.ts b/packages/material-ui/src/InputLabel/InputLabel.d.ts index c2356b8958154f..7cb5088c418c4b 100644 --- a/packages/material-ui/src/InputLabel/InputLabel.d.ts +++ b/packages/material-ui/src/InputLabel/InputLabel.d.ts @@ -26,4 +26,6 @@ export type InputLabelClassKey = | 'filled' | 'outlined'; -export default class InputLabel extends React.Component {} +declare const InputLabel: React.ComponentType; + +export default InputLabel;