diff --git a/docs/src/pages/lab/slider/slider.md b/docs/src/pages/lab/slider/slider.md
index 877122c2b6e515..94dfeb4f30755d 100644
--- a/docs/src/pages/lab/slider/slider.md
+++ b/docs/src/pages/lab/slider/slider.md
@@ -7,16 +7,21 @@ components: Slider
A [slider](https://material.io/guidelines/components/sliders.html) is an interface for users to input a value in a range. Sliders can be continuous or discrete and can be enabled or disabled.
## Simple slider
+
{{"demo": "pages/lab/slider/SimpleSlider.js"}}
## Slider with steps
+
{{"demo": "pages/lab/slider/StepSlider.js"}}
## Disabled slider
+
{{"demo": "pages/lab/slider/DisabledSlider.js"}}
## Vertical slider
+
{{"demo": "pages/lab/slider/VerticalSlider.js"}}
## Reverse slider
-{{"demo": "pages/lab/slider/ReverseSlider.js"}}
\ No newline at end of file
+
+{{"demo": "pages/lab/slider/ReverseSlider.js"}}
diff --git a/docs/src/pages/lab/speed-dial/OpenIconSpeedDial.js b/docs/src/pages/lab/speed-dial/OpenIconSpeedDial.js
index 4b66f462dc58ff..cd42b725909601 100644
--- a/docs/src/pages/lab/speed-dial/OpenIconSpeedDial.js
+++ b/docs/src/pages/lab/speed-dial/OpenIconSpeedDial.js
@@ -38,16 +38,16 @@ class OpenIconSpeedDial extends React.Component {
};
handleVisibility = () => {
- this.setState({
+ this.setState(state => ({
open: false,
- hidden: !this.state.hidden,
- });
+ hidden: !state.hidden,
+ }));
};
handleClick = () => {
- this.setState({
- open: !this.state.open,
- });
+ this.setState(state => ({
+ open: !state.open,
+ }));
};
handleOpen = () => {
diff --git a/docs/src/pages/lab/speed-dial/SpeedDials.js b/docs/src/pages/lab/speed-dial/SpeedDials.js
index a8f3f90720e018..f296b1d530f2cb 100644
--- a/docs/src/pages/lab/speed-dial/SpeedDials.js
+++ b/docs/src/pages/lab/speed-dial/SpeedDials.js
@@ -37,16 +37,16 @@ class SpeedDials extends React.Component {
};
handleVisibility = () => {
- this.setState({
+ this.setState(state => ({
open: false,
- hidden: !this.state.hidden,
- });
+ hidden: !state.hidden,
+ }));
};
handleClick = () => {
- this.setState({
- open: !this.state.open,
- });
+ this.setState(state => ({
+ open: !state.open,
+ }));
};
handleOpen = () => {
diff --git a/docs/src/pages/style/typography/Types.js b/docs/src/pages/style/typography/Types.js
index 6efac84f640758..fa1bf03045f87e 100644
--- a/docs/src/pages/style/typography/Types.js
+++ b/docs/src/pages/style/typography/Types.js
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import Typography from '@material-ui/core/Typography';
-import withTheme from '@material-ui/core/styles/withTheme';
+import { withStyles } from '@material-ui/core/styles';
const styles = {
root: {
@@ -10,9 +10,11 @@ const styles = {
},
};
-function Types() {
+function Types(props) {
+ const { classes } = props;
+
return (
-
+
Display 4
@@ -57,7 +59,7 @@ function Types() {
}
Types.propTypes = {
- theme: PropTypes.object.isRequired,
+ classes: PropTypes.object.isRequired,
};
-export default withTheme()(Types);
+export default withStyles(styles)(Types);
diff --git a/docs/src/pages/utils/popovers/AnchorPlayground.js b/docs/src/pages/utils/popovers/AnchorPlayground.js
index 529e17bd42aa99..9398a1227730a4 100644
--- a/docs/src/pages/utils/popovers/AnchorPlayground.js
+++ b/docs/src/pages/utils/popovers/AnchorPlayground.js
@@ -65,6 +65,8 @@ const inlineStyles = {
};
class AnchorPlayground extends React.Component {
+ anchorEl = null;
+
state = {
open: false,
anchorOriginVertical: 'top',
@@ -100,8 +102,6 @@ class AnchorPlayground extends React.Component {
});
};
- anchorEl = null;
-
render() {
const { classes } = this.props;
const {
diff --git a/docs/src/pages/utils/portal/SimplePortal.js b/docs/src/pages/utils/portal/SimplePortal.js
index 18a678490a0125..c08f64d0929b5d 100644
--- a/docs/src/pages/utils/portal/SimplePortal.js
+++ b/docs/src/pages/utils/portal/SimplePortal.js
@@ -15,16 +15,16 @@ const styles = theme => ({
});
class SimplePortal extends React.Component {
+ container = null;
+
state = {
show: false,
};
handleClick = () => {
- this.setState({ show: !this.state.show });
+ this.setState(state => ({ show: !state.show }));
};
- container = null;
-
render() {
const { classes } = this.props;
const { show } = this.state;
diff --git a/docs/src/pages/utils/transitions/SimpleCollapse.js b/docs/src/pages/utils/transitions/SimpleCollapse.js
index 807a0ed82c6ebc..433fae0e662073 100644
--- a/docs/src/pages/utils/transitions/SimpleCollapse.js
+++ b/docs/src/pages/utils/transitions/SimpleCollapse.js
@@ -32,7 +32,7 @@ class SimpleCollapse extends React.Component {
};
handleChange = () => {
- this.setState({ checked: !this.state.checked });
+ this.setState(state => ({ checked: !state.checked }));
};
render() {
diff --git a/docs/src/pages/utils/transitions/SimpleFade.js b/docs/src/pages/utils/transitions/SimpleFade.js
index 5d092dd79a4799..9fa64ed007ffde 100644
--- a/docs/src/pages/utils/transitions/SimpleFade.js
+++ b/docs/src/pages/utils/transitions/SimpleFade.js
@@ -29,7 +29,7 @@ class SimpleFade extends React.Component {
};
handleChange = () => {
- this.setState({ checked: !this.state.checked });
+ this.setState(state => ({ checked: !state.checked }));
};
render() {
diff --git a/docs/src/pages/utils/transitions/SimpleGrow.js b/docs/src/pages/utils/transitions/SimpleGrow.js
index decdd844201224..0674c42ab56608 100644
--- a/docs/src/pages/utils/transitions/SimpleGrow.js
+++ b/docs/src/pages/utils/transitions/SimpleGrow.js
@@ -32,7 +32,7 @@ class SimpleGrow extends React.Component {
};
handleChange = () => {
- this.setState({ checked: !this.state.checked });
+ this.setState(state => ({ checked: !state.checked }));
};
render() {
diff --git a/docs/src/pages/utils/transitions/SimpleSlide.js b/docs/src/pages/utils/transitions/SimpleSlide.js
index 424f29a73c67ff..b0ee2e3c107a2c 100644
--- a/docs/src/pages/utils/transitions/SimpleSlide.js
+++ b/docs/src/pages/utils/transitions/SimpleSlide.js
@@ -34,7 +34,7 @@ class SimpleSlide extends React.Component {
};
handleChange = () => {
- this.setState({ checked: !this.state.checked });
+ this.setState(state => ({ checked: !state.checked }));
};
render() {
diff --git a/docs/src/pages/utils/transitions/SimpleZoom.js b/docs/src/pages/utils/transitions/SimpleZoom.js
index cd0331a4e170c5..c51328de47817e 100644
--- a/docs/src/pages/utils/transitions/SimpleZoom.js
+++ b/docs/src/pages/utils/transitions/SimpleZoom.js
@@ -32,7 +32,7 @@ class SimpleZoom extends React.Component {
};
handleChange = () => {
- this.setState({ checked: !this.state.checked });
+ this.setState(state => ({ checked: !state.checked }));
};
render() {
diff --git a/examples/gatsby/src/withRoot.js b/examples/gatsby/src/withRoot.js
index 978b2d9e0de4d2..15fcda5f4f8859 100644
--- a/examples/gatsby/src/withRoot.js
+++ b/examples/gatsby/src/withRoot.js
@@ -6,6 +6,8 @@ import getPageContext from './getPageContext';
function withRoot(Component) {
class WithRoot extends React.Component {
+ pageContext = null;
+
constructor(props) {
super(props);
@@ -20,8 +22,6 @@ function withRoot(Component) {
}
}
- pageContext = null;
-
render() {
// MuiThemeProvider makes the theme available down the React tree thanks to React context.
return (
diff --git a/examples/nextjs/src/withRoot.js b/examples/nextjs/src/withRoot.js
index 6991e050f3a178..579b728752e038 100644
--- a/examples/nextjs/src/withRoot.js
+++ b/examples/nextjs/src/withRoot.js
@@ -6,6 +6,8 @@ import getPageContext from './getPageContext';
function withRoot(Component) {
class WithRoot extends React.Component {
+ pageContext = null;
+
constructor(props) {
super(props);
@@ -20,8 +22,6 @@ function withRoot(Component) {
}
}
- pageContext = null;
-
render() {
// MuiThemeProvider makes the theme available down the React tree thanks to React context.
return (
diff --git a/package.json b/package.json
index ecf90b649a03c0..89809b416828ba 100644
--- a/package.json
+++ b/package.json
@@ -85,11 +85,11 @@
"clipboard-copy": "^2.0.0",
"cross-env": "^5.1.1",
"doctrine": "^2.0.0",
- "downshift": "^1.22.1",
+ "downshift": "^2.0.0",
"enzyme": "^3.2.0",
"enzyme-adapter-react-16": "^1.1.0",
- "eslint": "^4.11.0",
- "eslint-config-airbnb": "^16.1.0",
+ "eslint": "^5.0.0",
+ "eslint-config-airbnb": "^17.0.0",
"eslint-import-resolver-webpack": "^0.10.0",
"eslint-plugin-babel": "^5.0.0",
"eslint-plugin-flowtype": "^2.40.1",
@@ -142,14 +142,14 @@
"redux": "^4.0.0",
"redux-logger": "^3.0.6",
"rimraf": "^2.6.2",
- "rollup": "^0.59.4",
+ "rollup": "^0.61.0",
"rollup-plugin-babel": "^4.0.0-beta.4",
"rollup-plugin-commonjs": "^9.1.3",
"rollup-plugin-node-globals": "^1.2.1",
"rollup-plugin-node-resolve": "^3.3.0",
"rollup-plugin-size-snapshot": "^0.5.1",
"rollup-plugin-uglify": "^4.0.0",
- "sinon": "^5.0.3",
+ "sinon": "^5.0.0",
"size-limit": "^0.18.0",
"typescript": "^2.6.1",
"url-loader": "^1.0.1",
diff --git a/packages/material-ui-codemod/src/v0.15.0/import-path.js b/packages/material-ui-codemod/src/v0.15.0/import-path.js
index 54e7d336be5a16..64cfa1138cd087 100644
--- a/packages/material-ui-codemod/src/v0.15.0/import-path.js
+++ b/packages/material-ui-codemod/src/v0.15.0/import-path.js
@@ -62,7 +62,9 @@ const pathBasePackage = ['material-ui/lib/', 'material-ui/'];
function getPathsBase(path) {
if (path.indexOf(pathBaseSource[0]) === 0) {
return pathBaseSource;
- } else if (path.indexOf(pathBasePackage[0]) === 0) {
+ }
+
+ if (path.indexOf(pathBasePackage[0]) === 0) {
return pathBasePackage;
}
diff --git a/packages/material-ui-lab/src/Slider/Slider.js b/packages/material-ui-lab/src/Slider/Slider.js
index d80f61234e8f07..5b9249d08b08c6 100644
--- a/packages/material-ui-lab/src/Slider/Slider.js
+++ b/packages/material-ui-lab/src/Slider/Slider.js
@@ -207,18 +207,6 @@ if (process.env.NODE_ENV !== 'production' && !React.createContext) {
class Slider extends React.Component {
state = { currentState: 'initial' };
- static getDerivedStateFromProps(nextProps, prevState) {
- if (nextProps.disabled) {
- return { currentState: 'disabled' };
- }
-
- if (!nextProps.disabled && prevState.currentState === 'disabled') {
- return { currentState: 'normal' };
- }
-
- return null;
- }
-
componentDidMount() {
if (this.container) {
this.container.addEventListener('touchstart', preventPageScrolling, { passive: false });
@@ -229,51 +217,16 @@ class Slider extends React.Component {
this.container.removeEventListener('touchstart', preventPageScrolling, { passive: false });
}
- emitChange(event, rawValue, callback) {
- const { step, value: previousValue, onChange, disabled } = this.props;
- let value = rawValue;
-
- if (disabled) {
- return;
- }
-
- if (step) {
- value = roundToStep(rawValue, step);
- } else {
- value = Number(rawValue.toFixed(3));
- }
-
- if (typeof onChange === 'function' && value !== previousValue) {
- onChange(event, value);
-
- if (typeof callback === 'function') {
- callback();
- }
+ static getDerivedStateFromProps(nextProps, prevState) {
+ if (nextProps.disabled) {
+ return { currentState: 'disabled' };
}
- }
-
- calculateTrackAfterStyles(percent) {
- const { currentState } = this.state;
- switch (currentState) {
- case 'activated':
- return `calc(100% - ${percent === 0 ? 7 : 5}px)`;
- case 'disabled':
- return `calc(${100 - percent}% - 6px)`;
- default:
- return 'calc(100% - 5px)';
+ if (!nextProps.disabled && prevState.currentState === 'disabled') {
+ return { currentState: 'normal' };
}
- }
-
- calculateTrackBeforeStyles(percent) {
- const { currentState } = this.state;
- switch (currentState) {
- case 'disabled':
- return `calc(${percent}% - 6px)`;
- default:
- return `${percent}%`;
- }
+ return null;
}
handleKeyDown = event => {
@@ -378,6 +331,53 @@ class Slider extends React.Component {
this.emitChange(event, value);
};
+ emitChange(event, rawValue, callback) {
+ const { step, value: previousValue, onChange, disabled } = this.props;
+ let value = rawValue;
+
+ if (disabled) {
+ return;
+ }
+
+ if (step) {
+ value = roundToStep(rawValue, step);
+ } else {
+ value = Number(rawValue.toFixed(3));
+ }
+
+ if (typeof onChange === 'function' && value !== previousValue) {
+ onChange(event, value);
+
+ if (typeof callback === 'function') {
+ callback();
+ }
+ }
+ }
+
+ calculateTrackAfterStyles(percent) {
+ const { currentState } = this.state;
+
+ switch (currentState) {
+ case 'activated':
+ return `calc(100% - ${percent === 0 ? 7 : 5}px)`;
+ case 'disabled':
+ return `calc(${100 - percent}% - 6px)`;
+ default:
+ return 'calc(100% - 5px)';
+ }
+ }
+
+ calculateTrackBeforeStyles(percent) {
+ const { currentState } = this.state;
+
+ switch (currentState) {
+ case 'disabled':
+ return `calc(${percent}% - 6px)`;
+ default:
+ return `${percent}%`;
+ }
+ }
+
playJumpAnimation() {
this.setState({ currentState: 'jumped' }, () => {
setTimeout(() => {
diff --git a/packages/material-ui/src/ButtonBase/ButtonBase.js b/packages/material-ui/src/ButtonBase/ButtonBase.js
index e3895a0819e5ec..dc96c98f997baa 100644
--- a/packages/material-ui/src/ButtonBase/ButtonBase.js
+++ b/packages/material-ui/src/ButtonBase/ButtonBase.js
@@ -55,29 +55,47 @@ if (process.env.NODE_ENV !== 'production' && !React.createContext) {
* It contains a load of style reset and some focus/ripple logic.
*/
class ButtonBase extends React.Component {
- state = {};
+ ripple = null;
- static getDerivedStateFromProps(nextProps, prevState) {
- if (typeof prevState.focusVisible === 'undefined') {
- return {
- focusVisible: false,
- lastDisabled: nextProps.disabled,
- };
+ keyDown = false; // Used to help track keyboard activation keyDown
+
+ button = null;
+
+ focusVisibleTimeout = null;
+
+ focusVisibleCheckTime = 50;
+
+ focusVisibleMaxCheckTimes = 5;
+
+ handleMouseDown = createRippleHandler(this, 'MouseDown', 'start', () => {
+ clearTimeout(this.focusVisibleTimeout);
+ if (this.state.focusVisible) {
+ this.setState({ focusVisible: false });
}
+ });
- // The blur won't fire when the disabled state is set on a focused input.
- // We need to book keep the focused state manually.
- if (!prevState.prevState && nextProps.disabled && prevState.focusVisible) {
- return {
- focusVisible: false,
- lastDisabled: nextProps.disabled,
- };
+ handleMouseUp = createRippleHandler(this, 'MouseUp', 'stop');
+
+ handleMouseLeave = createRippleHandler(this, 'MouseLeave', 'stop', event => {
+ if (this.state.focusVisible) {
+ event.preventDefault();
}
+ });
- return {
- lastDisabled: nextProps.disabled,
- };
- }
+ handleTouchStart = createRippleHandler(this, 'TouchStart', 'start');
+
+ handleTouchEnd = createRippleHandler(this, 'TouchEnd', 'stop');
+
+ handleTouchMove = createRippleHandler(this, 'TouchMove', 'stop');
+
+ handleBlur = createRippleHandler(this, 'Blur', 'stop', () => {
+ clearTimeout(this.focusVisibleTimeout);
+ if (this.state.focusVisible) {
+ this.setState({ focusVisible: false });
+ }
+ });
+
+ state = {};
componentDidMount() {
this.button = ReactDOM.findDOMNode(this);
@@ -109,6 +127,10 @@ class ButtonBase extends React.Component {
clearTimeout(this.focusVisibleTimeout);
}
+ onRippleRef = node => {
+ this.ripple = node;
+ };
+
onFocusVisibleHandler = event => {
this.keyDown = false;
this.setState({ focusVisible: true });
@@ -118,16 +140,27 @@ class ButtonBase extends React.Component {
}
};
- onRippleRef = node => {
- this.ripple = node;
- };
+ static getDerivedStateFromProps(nextProps, prevState) {
+ if (typeof prevState.focusVisible === 'undefined') {
+ return {
+ focusVisible: false,
+ lastDisabled: nextProps.disabled,
+ };
+ }
- ripple = null;
- keyDown = false; // Used to help track keyboard activation keyDown
- button = null;
- focusVisibleTimeout = null;
- focusVisibleCheckTime = 50;
- focusVisibleMaxCheckTimes = 5;
+ // The blur won't fire when the disabled state is set on a focused input.
+ // We need to book keep the focused state manually.
+ if (!prevState.prevState && nextProps.disabled && prevState.focusVisible) {
+ return {
+ focusVisible: false,
+ lastDisabled: nextProps.disabled,
+ };
+ }
+
+ return {
+ lastDisabled: nextProps.disabled,
+ };
+ }
handleKeyDown = event => {
const { component, focusRipple, onKeyDown, onClick } = this.props;
@@ -179,34 +212,6 @@ class ButtonBase extends React.Component {
}
};
- handleMouseDown = createRippleHandler(this, 'MouseDown', 'start', () => {
- clearTimeout(this.focusVisibleTimeout);
- if (this.state.focusVisible) {
- this.setState({ focusVisible: false });
- }
- });
-
- handleMouseUp = createRippleHandler(this, 'MouseUp', 'stop');
-
- handleMouseLeave = createRippleHandler(this, 'MouseLeave', 'stop', event => {
- if (this.state.focusVisible) {
- event.preventDefault();
- }
- });
-
- handleTouchStart = createRippleHandler(this, 'TouchStart', 'start');
-
- handleTouchEnd = createRippleHandler(this, 'TouchEnd', 'stop');
-
- handleTouchMove = createRippleHandler(this, 'TouchMove', 'stop');
-
- handleBlur = createRippleHandler(this, 'Blur', 'stop', () => {
- clearTimeout(this.focusVisibleTimeout);
- if (this.state.focusVisible) {
- this.setState({ focusVisible: false });
- }
- });
-
handleFocus = event => {
if (this.props.disabled) {
return;
diff --git a/packages/material-ui/src/ButtonBase/TouchRipple.js b/packages/material-ui/src/ButtonBase/TouchRipple.js
index 24cbb84ebe7b1b..efe6303e7a7502 100644
--- a/packages/material-ui/src/ButtonBase/TouchRipple.js
+++ b/packages/material-ui/src/ButtonBase/TouchRipple.js
@@ -88,7 +88,18 @@ export const styles = theme => ({
});
class TouchRipple extends React.PureComponent {
+ // Used to filter out mouse emulated events on mobile.
+ ignoringMouseDown = false;
+
+ // We use a timer in order to only show the ripples for touch "click" like events.
+ // We don't want to display the ripple for touch scroll events.
+ startTimer = null;
+
+ // This is the hook called once the previous timeout is ready.
+ startTimerCommit = null;
+
state = {
+ // eslint-disable-next-line react/no-unused-state
nextKey: 0,
ripples: [],
};
@@ -97,14 +108,6 @@ class TouchRipple extends React.PureComponent {
clearTimeout(this.startTimer);
}
- // Used to filter out mouse emulated events on mobile.
- ignoringMouseDown = false;
- // We use a timer in order to only show the ripples for touch "click" like events.
- // We don't want to display the ripple for touch scroll events.
- startTimer = null;
- // This is the hook called once the previous timeout is ready.
- startTimerCommit = null;
-
pulsate = () => {
this.start({}, { pulsate: true });
};
@@ -155,7 +158,7 @@ class TouchRipple extends React.PureComponent {
}
if (center) {
- rippleSize = Math.sqrt((2 * Math.pow(rect.width, 2) + Math.pow(rect.height, 2)) / 3);
+ rippleSize = Math.sqrt((2 * rect.width ** 2 + rect.height ** 2) / 3);
// For some reason the animation is broken on Mobile Chrome if the size if even.
if (rippleSize % 2 === 0) {
@@ -166,7 +169,7 @@ class TouchRipple extends React.PureComponent {
Math.max(Math.abs((element ? element.clientWidth : 0) - rippleX), rippleX) * 2 + 2;
const sizeY =
Math.max(Math.abs((element ? element.clientHeight : 0) - rippleY), rippleY) * 2 + 2;
- rippleSize = Math.sqrt(Math.pow(sizeX, 2) + Math.pow(sizeY, 2));
+ rippleSize = Math.sqrt(sizeX ** 2 + sizeY ** 2);
}
// Touche devices
@@ -189,32 +192,27 @@ class TouchRipple extends React.PureComponent {
startCommit = params => {
const { pulsate, rippleX, rippleY, rippleSize, cb } = params;
- let ripples = this.state.ripples;
-
- // Add a ripple to the ripples array.
- ripples = [
- ...ripples,
- ,
- ];
- this.setState(
- {
- nextKey: this.state.nextKey + 1,
- ripples,
- },
- cb,
- );
+ this.setState(state => {
+ return {
+ nextKey: state.nextKey + 1,
+ ripples: [
+ ...state.ripples,
+ ,
+ ],
+ };
+ }, cb);
};
stop = (event, cb) => {
diff --git a/packages/material-ui/src/ClickAwayListener/ClickAwayListener.js b/packages/material-ui/src/ClickAwayListener/ClickAwayListener.js
index e79a3533c54a54..a73e00dd594804 100644
--- a/packages/material-ui/src/ClickAwayListener/ClickAwayListener.js
+++ b/packages/material-ui/src/ClickAwayListener/ClickAwayListener.js
@@ -11,6 +11,10 @@ import ownerDocument from '../utils/ownerDocument';
* For instance, if you need to hide a menu when people click anywhere else on your page.
*/
class ClickAwayListener extends React.Component {
+ node = null;
+
+ mounted = null;
+
componentDidMount() {
this.node = ReactDOM.findDOMNode(this);
this.mounted = true;
@@ -20,9 +24,6 @@ class ClickAwayListener extends React.Component {
this.mounted = false;
}
- node = null;
- mounted = null;
-
handleClickAway = event => {
// Ignore events that have been `event.preventDefault()` marked.
if (event.defaultPrevented) {
diff --git a/packages/material-ui/src/Collapse/Collapse.js b/packages/material-ui/src/Collapse/Collapse.js
index bbc5ff661ded43..3c0244b21139fa 100644
--- a/packages/material-ui/src/Collapse/Collapse.js
+++ b/packages/material-ui/src/Collapse/Collapse.js
@@ -32,14 +32,16 @@ export const styles = theme => ({
* It uses [react-transition-group](https://github.com/reactjs/react-transition-group) internally.
*/
class Collapse extends React.Component {
+ wrapper = null;
+
+ autoTransitionDuration = null;
+
+ timer = null;
+
componentWillUnmount() {
clearTimeout(this.timer);
}
- wrapper = null;
- autoTransitionDuration = undefined;
- timer = null;
-
handleEnter = node => {
node.style.height = this.props.collapsedHeight;
diff --git a/packages/material-ui/src/CssBaseline/CssBaseline.js b/packages/material-ui/src/CssBaseline/CssBaseline.js
index 97730441a366e1..dd5fd1187f1c7a 100644
--- a/packages/material-ui/src/CssBaseline/CssBaseline.js
+++ b/packages/material-ui/src/CssBaseline/CssBaseline.js
@@ -1,3 +1,5 @@
+/* eslint-disable react/no-unused-prop-types */
+
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '../styles';
diff --git a/packages/material-ui/src/DialogActions/DialogActions.test.js b/packages/material-ui/src/DialogActions/DialogActions.test.js
index 75fbdf46f47993..8fb16efa6fc2a6 100644
--- a/packages/material-ui/src/DialogActions/DialogActions.test.js
+++ b/packages/material-ui/src/DialogActions/DialogActions.test.js
@@ -37,7 +37,9 @@ describe('', () => {
it('should render children with the button class wrapped in a div with the action class', () => {
const wrapper = shallow(
-
+
,
);
const button = wrapper.childAt(0);
@@ -50,8 +52,12 @@ describe('', () => {
const showButton = true;
const wrapper = shallow(
- {showButton ? : null}
- {!showButton ? : null}
+ {showButton ? (
+
+ ) : null}
+ {!showButton ? : null}
,
);
diff --git a/packages/material-ui/src/Drawer/Drawer.js b/packages/material-ui/src/Drawer/Drawer.js
index 52b1c64ad07e8c..7761c61325e7d4 100644
--- a/packages/material-ui/src/Drawer/Drawer.js
+++ b/packages/material-ui/src/Drawer/Drawer.js
@@ -89,15 +89,15 @@ export const styles = theme => ({
* when `variant="temporary"` is set.
*/
class Drawer extends React.Component {
- componentDidMount() {
- this.mounted = true;
- }
-
// Let's assume that the Drawer will always be rendered on user space.
- // We use that state is order to skip the appear transition during the
+ // We use this state is order to skip the appear transition during the
// initial mount of the component.
mounted = false;
+ componentDidMount() {
+ this.mounted = true;
+ }
+
render() {
const {
anchor: anchorProp,
diff --git a/packages/material-ui/src/ExpansionPanel/ExpansionPanel.js b/packages/material-ui/src/ExpansionPanel/ExpansionPanel.js
index 8d327bb8236f20..d439da8170d18c 100644
--- a/packages/material-ui/src/ExpansionPanel/ExpansionPanel.js
+++ b/packages/material-ui/src/ExpansionPanel/ExpansionPanel.js
@@ -77,6 +77,8 @@ export const styles = theme => {
};
class ExpansionPanel extends React.Component {
+ isControlled = null;
+
constructor(props) {
super(props);
@@ -89,8 +91,6 @@ class ExpansionPanel extends React.Component {
state = {};
- isControlled = null;
-
handleChange = event => {
const expanded = this.isControlled ? this.props.expanded : this.state.expanded;
diff --git a/packages/material-ui/src/ExpansionPanelActions/ExpansionPanelActions.test.js b/packages/material-ui/src/ExpansionPanelActions/ExpansionPanelActions.test.js
index 4489d883e50cc8..32621fab6cf824 100644
--- a/packages/material-ui/src/ExpansionPanelActions/ExpansionPanelActions.test.js
+++ b/packages/material-ui/src/ExpansionPanelActions/ExpansionPanelActions.test.js
@@ -39,7 +39,9 @@ describe('', () => {
it('should render children with the button class wrapped in a div with the action class', () => {
const wrapper = shallow(
-
+
,
);
const button = wrapper.childAt(0);
@@ -55,7 +57,7 @@ describe('', () => {
it('should render a valid children', () => {
const wrapper = shallow(
-
+
{null}
,
);
diff --git a/packages/material-ui/src/GridListTile/GridListTile.js b/packages/material-ui/src/GridListTile/GridListTile.js
index 2a82910c86d73c..97a971fc318c6c 100644
--- a/packages/material-ui/src/GridListTile/GridListTile.js
+++ b/packages/material-ui/src/GridListTile/GridListTile.js
@@ -31,6 +31,12 @@ export const styles = {
};
class GridListTile extends React.Component {
+ imgElement = null;
+
+ handleResize = debounce(() => {
+ this.fit();
+ }, 166); // Corresponds to 10 frames at 60 Hz.
+
componentDidMount() {
this.ensureImageCover();
}
@@ -43,12 +49,6 @@ class GridListTile extends React.Component {
this.handleResize.clear();
}
- imgElement = null;
-
- handleResize = debounce(() => {
- this.fit();
- }, 166); // Corresponds to 10 frames at 60 Hz.
-
fit = () => {
const imgElement = this.imgElement;
diff --git a/packages/material-ui/src/Grow/Grow.js b/packages/material-ui/src/Grow/Grow.js
index befede91acb004..cb6464636ea6ab 100644
--- a/packages/material-ui/src/Grow/Grow.js
+++ b/packages/material-ui/src/Grow/Grow.js
@@ -7,7 +7,7 @@ import withTheme from '../styles/withTheme';
import { reflow, getTransitionProps } from '../transitions/utils';
function getScale(value) {
- return `scale(${value}, ${Math.pow(value, 2)})`;
+ return `scale(${value}, ${value ** 2})`;
}
const styles = {
@@ -26,13 +26,14 @@ const styles = {
* It uses [react-transition-group](https://github.com/reactjs/react-transition-group) internally.
*/
class Grow extends React.Component {
+ autoTimeout = null;
+
+ timer = null;
+
componentWillUnmount() {
clearTimeout(this.timer);
}
- autoTimeout = undefined;
- timer = null;
-
handleEnter = node => {
const { theme, timeout } = this.props;
reflow(node); // So the animation always start from the start.
diff --git a/packages/material-ui/src/Input/Input.js b/packages/material-ui/src/Input/Input.js
index 9ca693ca4e3bd2..6483dd5665e129 100644
--- a/packages/material-ui/src/Input/Input.js
+++ b/packages/material-ui/src/Input/Input.js
@@ -217,6 +217,10 @@ function formControlState(props, context) {
}
class Input extends React.Component {
+ isControlled = this.props.value != null;
+
+ input = null; // Holds the input reference
+
constructor(props, context) {
super(props, context);
@@ -285,9 +289,6 @@ class Input extends React.Component {
} // else performed in the onChange
}
- isControlled = this.props.value != null;
- input = null; // Holds the input reference
-
handleFocus = event => {
// Fix a bug with IE11 where the focus/blur events are triggered
// while the input is disabled.
diff --git a/packages/material-ui/src/Input/Textarea.js b/packages/material-ui/src/Input/Textarea.js
index 9ec321ed76ff06..acea9db73d44eb 100644
--- a/packages/material-ui/src/Input/Textarea.js
+++ b/packages/material-ui/src/Input/Textarea.js
@@ -42,6 +42,18 @@ export const styles = {
* @ignore - internal component.
*/
class Textarea extends React.Component {
+ shadow = null;
+
+ singlelineShadow = null;
+
+ input = null;
+
+ value = null;
+
+ handleResize = debounce(() => {
+ this.syncHeightWithShadow();
+ }, 166); // Corresponds to 10 frames at 60 Hz.
+
constructor(props) {
super(props);
@@ -69,14 +81,40 @@ class Textarea extends React.Component {
this.handleResize.clear();
}
- shadow = null;
- singlelineShadow = null;
- input = null;
- value = null;
+ handleRefInput = node => {
+ this.input = node;
- handleResize = debounce(() => {
- this.syncHeightWithShadow();
- }, 166); // Corresponds to 10 frames at 60 Hz.
+ const { textareaRef } = this.props;
+ if (textareaRef) {
+ if (typeof textareaRef === 'function') {
+ textareaRef(node);
+ } else {
+ textareaRef.current = node;
+ }
+ }
+ };
+
+ handleRefSinglelineShadow = node => {
+ this.singlelineShadow = node;
+ };
+
+ handleRefShadow = node => {
+ this.shadow = node;
+ };
+
+ handleChange = event => {
+ this.value = event.target.value;
+
+ if (typeof this.props.value === 'undefined' && this.shadow) {
+ // The component is not controlled, we need to update the shallow value.
+ this.shadow.value = this.value;
+ this.syncHeightWithShadow();
+ }
+
+ if (this.props.onChange) {
+ this.props.onChange(event);
+ }
+ };
syncHeightWithShadow() {
const props = this.props;
@@ -113,41 +151,6 @@ class Textarea extends React.Component {
}
}
- handleRefInput = node => {
- this.input = node;
-
- const { textareaRef } = this.props;
- if (textareaRef) {
- if (typeof textareaRef === 'function') {
- textareaRef(node);
- } else {
- textareaRef.current = node;
- }
- }
- };
-
- handleRefSinglelineShadow = node => {
- this.singlelineShadow = node;
- };
-
- handleRefShadow = node => {
- this.shadow = node;
- };
-
- handleChange = event => {
- this.value = event.target.value;
-
- if (typeof this.props.value === 'undefined' && this.shadow) {
- // The component is not controlled, we need to update the shallow value.
- this.shadow.value = this.value;
- this.syncHeightWithShadow();
- }
-
- if (this.props.onChange) {
- this.props.onChange(event);
- }
- };
-
render() {
const {
classes,
diff --git a/packages/material-ui/src/Menu/Menu.js b/packages/material-ui/src/Menu/Menu.js
index a5e9d0cbfda9cb..7342cc9ab71a68 100644
--- a/packages/material-ui/src/Menu/Menu.js
+++ b/packages/material-ui/src/Menu/Menu.js
@@ -30,6 +30,8 @@ export const styles = {
};
class Menu extends React.Component {
+ menuList = null;
+
componentDidMount() {
if (this.props.open) {
this.focus();
@@ -44,8 +46,6 @@ class Menu extends React.Component {
return ReactDOM.findDOMNode(this.menuList.selectedItem);
};
- menuList = undefined;
-
focus = () => {
if (this.menuList && this.menuList.selectedItem) {
ReactDOM.findDOMNode(this.menuList.selectedItem).focus();
diff --git a/packages/material-ui/src/MenuList/MenuList.js b/packages/material-ui/src/MenuList/MenuList.js
index 50ff7a305a4ffc..a32ffbf2617150 100644
--- a/packages/material-ui/src/MenuList/MenuList.js
+++ b/packages/material-ui/src/MenuList/MenuList.js
@@ -8,8 +8,14 @@ import ownerDocument from '../utils/ownerDocument';
import List from '../List';
class MenuList extends React.Component {
+ list = null;
+
+ selectedItem = null;
+
+ blurTimer = null;
+
state = {
- currentTabIndex: undefined,
+ currentTabIndex: null,
};
componentDidMount() {
@@ -24,10 +30,6 @@ class MenuList extends React.Component {
this.setState({ currentTabIndex: index });
}
- list = undefined;
- selectedItem = undefined;
- blurTimer = undefined;
-
handleBlur = event => {
this.blurTimer = setTimeout(() => {
if (this.list) {
diff --git a/packages/material-ui/src/Modal/Modal.js b/packages/material-ui/src/Modal/Modal.js
index 81de306ba3935d..439191844e2347 100644
--- a/packages/material-ui/src/Modal/Modal.js
+++ b/packages/material-ui/src/Modal/Modal.js
@@ -44,6 +44,12 @@ if (process.env.NODE_ENV !== 'production' && !React.createContext) {
}
class Modal extends React.Component {
+ dialogElement = null;
+
+ mounted = false;
+
+ mountNode = null;
+
constructor(props) {
super(props);
@@ -52,21 +58,6 @@ class Modal extends React.Component {
};
}
- static getDerivedStateFromProps(nextProps) {
- if (nextProps.open) {
- return {
- exited: false,
- };
- } else if (!getHasTransition(nextProps)) {
- // Otherwise let handleExited take care of marking exited.
- return {
- exited: true,
- };
- }
-
- return null;
- }
-
componentDidMount() {
this.mounted = true;
if (this.props.open) {
@@ -95,9 +86,22 @@ class Modal extends React.Component {
}
}
- dialogElement = null;
- mounted = false;
- mountNode = null;
+ static getDerivedStateFromProps(nextProps) {
+ if (nextProps.open) {
+ return {
+ exited: false,
+ };
+ }
+
+ if (!getHasTransition(nextProps)) {
+ // Otherwise let handleExited take care of marking exited.
+ return {
+ exited: true,
+ };
+ }
+
+ return null;
+ }
handleRendered = () => {
this.autoFocus();
@@ -161,6 +165,18 @@ class Modal extends React.Component {
this.lastFocus = ownerDocument(this.mountNode).activeElement;
};
+ enforceFocus = () => {
+ if (this.props.disableEnforceFocus || !this.mounted || !this.isTopModal()) {
+ return;
+ }
+
+ const currentActiveElement = ownerDocument(this.mountNode).activeElement;
+
+ if (this.dialogElement && !this.dialogElement.contains(currentActiveElement)) {
+ this.dialogElement.focus();
+ }
+ };
+
autoFocus() {
if (this.props.disableAutoFocus) {
return;
@@ -204,18 +220,6 @@ class Modal extends React.Component {
}
}
- enforceFocus = () => {
- if (this.props.disableEnforceFocus || !this.mounted || !this.isTopModal()) {
- return;
- }
-
- const currentActiveElement = ownerDocument(this.mountNode).activeElement;
-
- if (this.dialogElement && !this.dialogElement.contains(currentActiveElement)) {
- this.dialogElement.focus();
- }
- };
-
isTopModal() {
return this.props.manager.isTopModal(this);
}
diff --git a/packages/material-ui/src/Popover/Popover.js b/packages/material-ui/src/Popover/Popover.js
index 399c669b8ae04d..e10c5bdd55904a 100644
--- a/packages/material-ui/src/Popover/Popover.js
+++ b/packages/material-ui/src/Popover/Popover.js
@@ -82,6 +82,17 @@ export const styles = {
};
class Popover extends React.Component {
+ transitionEl = null;
+
+ handleGetOffsetTop = getOffsetTop;
+
+ handleGetOffsetLeft = getOffsetLeft;
+
+ handleResize = debounce(() => {
+ const element = ReactDOM.findDOMNode(this.transitionEl);
+ this.setPositioningStyles(element);
+ }, 166); // Corresponds to 10 frames at 60 Hz.
+
componentDidMount() {
if (this.props.action) {
this.props.action({
@@ -247,12 +258,6 @@ class Popover extends React.Component {
};
}
- transitionEl = undefined;
-
- handleGetOffsetTop = getOffsetTop;
-
- handleGetOffsetLeft = getOffsetLeft;
-
handleEnter = element => {
if (this.props.onEnter) {
this.props.onEnter(element);
@@ -261,11 +266,6 @@ class Popover extends React.Component {
this.setPositioningStyles(element);
};
- handleResize = debounce(() => {
- const element = ReactDOM.findDOMNode(this.transitionEl);
- this.setPositioningStyles(element);
- }, 166); // Corresponds to 10 frames at 60 Hz.
-
render() {
const {
action,
@@ -378,8 +378,8 @@ Popover.propTypes = {
* the application's client area.
*/
anchorPosition: PropTypes.shape({
- top: PropTypes.number,
left: PropTypes.number,
+ top: PropTypes.number,
}),
/*
* This determines which anchor prop to refer to to set
diff --git a/packages/material-ui/src/Select/SelectInput.js b/packages/material-ui/src/Select/SelectInput.js
index 71071df5f57f7f..6e77209b236d24 100644
--- a/packages/material-ui/src/Select/SelectInput.js
+++ b/packages/material-ui/src/Select/SelectInput.js
@@ -9,6 +9,12 @@ import { isFilled } from '../Input/Input';
* @ignore - internal component.
*/
class SelectInput extends React.Component {
+ ignoreNextBlur = false;
+
+ displayNode = null;
+
+ isOpenControlled = this.props.open !== undefined;
+
state = {
menuMinWidth: null,
open: false,
@@ -28,25 +34,22 @@ class SelectInput extends React.Component {
}
}
- ignoreNextBlur = false;
- displayNode = null;
- isOpenControlled = this.props.open !== undefined;
-
- update = this.isOpenControlled
- ? ({ event, open }) => {
- if (open) {
- this.props.onOpen(event);
- } else {
- this.props.onClose(event);
- }
+ update = ({ event, open }) => {
+ if (this.isOpenControlled) {
+ if (open) {
+ this.props.onOpen(event);
+ } else {
+ this.props.onClose(event);
}
- : ({ open }) => {
- this.setState({
- // Perfom the layout computation outside of the render method.
- menuMinWidth: this.props.autoWidth ? null : this.displayNode.clientWidth,
- open,
- });
- };
+ return;
+ }
+
+ this.setState({
+ // Perfom the layout computation outside of the render method.
+ menuMinWidth: this.props.autoWidth ? null : this.displayNode.clientWidth,
+ open,
+ });
+ };
handleClick = event => {
// Opening the menu is going to blur the. It will be focused back when closed.
diff --git a/packages/material-ui/src/Slide/Slide.js b/packages/material-ui/src/Slide/Slide.js
index 5ae681767f59f4..52b5f3fbc1d0af 100644
--- a/packages/material-ui/src/Slide/Slide.js
+++ b/packages/material-ui/src/Slide/Slide.js
@@ -45,9 +45,13 @@ function getTranslateValue(props, node) {
if (direction === 'left') {
return `translateX(100vw) translateX(-${rect.left - offsetX}px)`;
- } else if (direction === 'right') {
+ }
+
+ if (direction === 'right') {
return `translateX(-${rect.left + rect.width + GUTTER - offsetX}px)`;
- } else if (direction === 'up') {
+ }
+
+ if (direction === 'up') {
return `translateY(100vh) translateY(-${rect.top - offsetY}px)`;
}
@@ -69,6 +73,22 @@ export function setTranslateValue(props, node) {
* It uses [react-transition-group](https://github.com/reactjs/react-transition-group) internally.
*/
class Slide extends React.Component {
+ mounted = false;
+
+ transition = null;
+
+ handleResize = debounce(() => {
+ // Skip configuration where the position is screen size invariant.
+ if (this.props.in || this.props.direction === 'down' || this.props.direction === 'right') {
+ return;
+ }
+
+ const node = ReactDOM.findDOMNode(this.transition);
+ if (node) {
+ setTranslateValue(this.props, node);
+ }
+ }, 166); // Corresponds to 10 frames at 60 Hz.
+
componentDidMount() {
// state.mounted handle SSR, once the component is mounted, we need
// to properly hide it.
@@ -93,29 +113,6 @@ class Slide extends React.Component {
this.handleResize.clear();
}
- mounted = false;
- transition = null;
-
- updatePosition() {
- const node = ReactDOM.findDOMNode(this.transition);
- if (node) {
- node.style.visibility = 'inherit';
- setTranslateValue(this.props, node);
- }
- }
-
- handleResize = debounce(() => {
- // Skip configuration where the position is screen size invariant.
- if (this.props.in || this.props.direction === 'down' || this.props.direction === 'right') {
- return;
- }
-
- const node = ReactDOM.findDOMNode(this.transition);
- if (node) {
- setTranslateValue(this.props, node);
- }
- }, 166); // Corresponds to 10 frames at 60 Hz.
-
handleEnter = node => {
setTranslateValue(this.props, node);
reflow(node);
@@ -177,6 +174,14 @@ class Slide extends React.Component {
}
};
+ updatePosition() {
+ const node = ReactDOM.findDOMNode(this.transition);
+ if (node) {
+ node.style.visibility = 'inherit';
+ setTranslateValue(this.props, node);
+ }
+ }
+
render() {
const {
children,
diff --git a/packages/material-ui/src/Snackbar/Snackbar.js b/packages/material-ui/src/Snackbar/Snackbar.js
index bc48782c46d9ea..09c689489226c0 100644
--- a/packages/material-ui/src/Snackbar/Snackbar.js
+++ b/packages/material-ui/src/Snackbar/Snackbar.js
@@ -92,23 +92,9 @@ if (process.env.NODE_ENV !== 'production' && !React.createContext) {
}
class Snackbar extends React.Component {
- state = {};
-
- static getDerivedStateFromProps(nextProps, prevState) {
- if (typeof prevState.exited === 'undefined') {
- return {
- exited: !nextProps.open,
- };
- }
-
- if (nextProps.open) {
- return {
- exited: false,
- };
- }
+ timerAutoHide = null;
- return null;
- }
+ state = {};
componentDidMount() {
if (this.props.open) {
@@ -130,6 +116,22 @@ class Snackbar extends React.Component {
clearTimeout(this.timerAutoHide);
}
+ static getDerivedStateFromProps(nextProps, prevState) {
+ if (typeof prevState.exited === 'undefined') {
+ return {
+ exited: !nextProps.open,
+ };
+ }
+
+ if (nextProps.open) {
+ return {
+ exited: false,
+ };
+ }
+
+ return null;
+ }
+
// Timer that controls delay before snackbar auto hides
setAutoHideTimer(autoHideDuration = null) {
if (!this.props.onClose || this.props.autoHideDuration == null) {
@@ -146,8 +148,6 @@ class Snackbar extends React.Component {
}, autoHideDuration || this.props.autoHideDuration || 0);
}
- timerAutoHide = null;
-
handleMouseEnter = event => {
if (this.props.onMouseEnter) {
this.props.onMouseEnter(event);
diff --git a/packages/material-ui/src/StepContent/StepContent.test.js b/packages/material-ui/src/StepContent/StepContent.test.js
index aa600c20cbcba2..5376a839ab3e66 100644
--- a/packages/material-ui/src/StepContent/StepContent.test.js
+++ b/packages/material-ui/src/StepContent/StepContent.test.js
@@ -1,8 +1,8 @@
import React from 'react';
import { assert } from 'chai';
import { createShallow, createMount } from '../test-utils';
-import StepContent from '../StepContent';
import Collapse from '../Collapse';
+import StepContent from './StepContent';
describe('', () => {
let shallow;
diff --git a/packages/material-ui/src/StepIcon/StepIcon.test.js b/packages/material-ui/src/StepIcon/StepIcon.test.js
index 6d3679b9f3bb33..a103f5b89206db 100644
--- a/packages/material-ui/src/StepIcon/StepIcon.test.js
+++ b/packages/material-ui/src/StepIcon/StepIcon.test.js
@@ -3,8 +3,8 @@ import { assert } from 'chai';
import CheckCircle from '../internal/svg-icons/CheckCircle';
import Warning from '../internal/svg-icons/Warning';
import { createShallow, createMount } from '../test-utils';
-import StepIcon from '../StepIcon';
import StepPositionIcon from './StepPositionIcon';
+import StepIcon from './StepIcon';
describe('', () => {
let shallow;
diff --git a/packages/material-ui/src/StepLabel/StepLabel.test.js b/packages/material-ui/src/StepLabel/StepLabel.test.js
index a262854e7a94e7..f4238c35548278 100644
--- a/packages/material-ui/src/StepLabel/StepLabel.test.js
+++ b/packages/material-ui/src/StepLabel/StepLabel.test.js
@@ -2,8 +2,8 @@ import React from 'react';
import { assert } from 'chai';
import { createShallow, createMount, getClasses } from '../test-utils';
import Typography from '../Typography';
-import StepLabel from '../StepLabel';
import StepIcon from '../StepIcon';
+import StepLabel from './StepLabel';
describe('', () => {
let shallow;
diff --git a/packages/material-ui/src/SwipeableDrawer/SwipeableDrawer.js b/packages/material-ui/src/SwipeableDrawer/SwipeableDrawer.js
index e52a34fbfadfb0..fc82f4176c2cab 100644
--- a/packages/material-ui/src/SwipeableDrawer/SwipeableDrawer.js
+++ b/packages/material-ui/src/SwipeableDrawer/SwipeableDrawer.js
@@ -30,27 +30,17 @@ if (process.env.NODE_ENV !== 'production' && !React.createContext) {
}
class SwipeableDrawer extends React.Component {
- state = {};
+ backdrop = null;
- static getDerivedStateFromProps(nextProps, prevState) {
- if (typeof prevState.maybeSwiping === 'undefined') {
- return {
- maybeSwiping: false,
- open: nextProps.open,
- };
- }
+ paper = null;
- if (!nextProps.open && prevState.open) {
- return {
- maybeSwiping: false,
- open: nextProps.open,
- };
- }
+ isSwiping = null;
- return {
- open: nextProps.open,
- };
- }
+ startX = null;
+
+ startY = null;
+
+ state = {};
componentDidMount() {
if (this.props.variant === 'temporary') {
@@ -81,6 +71,26 @@ class SwipeableDrawer extends React.Component {
}
}
+ static getDerivedStateFromProps(nextProps, prevState) {
+ if (typeof prevState.maybeSwiping === 'undefined') {
+ return {
+ maybeSwiping: false,
+ open: nextProps.open,
+ };
+ }
+
+ if (!nextProps.open && prevState.open) {
+ return {
+ maybeSwiping: false,
+ open: nextProps.open,
+ };
+ }
+
+ return {
+ open: nextProps.open,
+ };
+ }
+
getMaxTranslate() {
return isHorizontal(this.props) ? this.paper.clientWidth : this.paper.clientHeight;
}
@@ -298,11 +308,13 @@ class SwipeableDrawer extends React.Component {
this.isSwiping = null;
};
- backdrop = null;
- paper = null;
- isSwiping = null;
- startX = null;
- startY = null;
+ handleBackdropRef = node => {
+ this.backdrop = node ? ReactDOM.findDOMNode(node) : null;
+ };
+
+ handlePaperRef = node => {
+ this.paper = node ? ReactDOM.findDOMNode(node) : null;
+ };
listenTouchStart() {
document.body.addEventListener('touchstart', this.handleBodyTouchStart);
@@ -318,14 +330,6 @@ class SwipeableDrawer extends React.Component {
document.body.removeEventListener('touchcancel', this.handleBodyTouchEnd);
}
- handleBackdropRef = node => {
- this.backdrop = node ? ReactDOM.findDOMNode(node) : null;
- };
-
- handlePaperRef = node => {
- this.paper = node ? ReactDOM.findDOMNode(node) : null;
- };
-
render() {
const {
disableBackdropTransition,
diff --git a/packages/material-ui/src/Tab/Tab.js b/packages/material-ui/src/Tab/Tab.js
index fdbaf42a4dcb30..bdea8c4d5511d3 100644
--- a/packages/material-ui/src/Tab/Tab.js
+++ b/packages/material-ui/src/Tab/Tab.js
@@ -91,6 +91,8 @@ export const styles = theme => ({
});
class Tab extends React.Component {
+ label = null;
+
state = {
labelWrapped: false,
};
@@ -122,8 +124,6 @@ class Tab extends React.Component {
}
};
- label = undefined;
-
checkTextWrap = () => {
if (this.label) {
const labelWrapped = this.label.getClientRects().length > 1;
diff --git a/packages/material-ui/src/TablePagination/TablePagination.test.js b/packages/material-ui/src/TablePagination/TablePagination.test.js
index d63b3c24c03283..48f4e9c4fd7340 100644
--- a/packages/material-ui/src/TablePagination/TablePagination.test.js
+++ b/packages/material-ui/src/TablePagination/TablePagination.test.js
@@ -7,9 +7,9 @@ import Select from '../Select';
import IconButton from '../IconButton';
import TableFooter from '../TableFooter';
import TableCell from '../TableCell';
-import TablePagination from '../TablePagination';
import Typography from '../Typography';
import TableRow from '../TableRow';
+import TablePagination from './TablePagination';
describe('', () => {
const noop = () => {};
diff --git a/packages/material-ui/src/Tabs/ScrollbarSize.js b/packages/material-ui/src/Tabs/ScrollbarSize.js
index 68b31343da797f..8906bf42bcb115 100644
--- a/packages/material-ui/src/Tabs/ScrollbarSize.js
+++ b/packages/material-ui/src/Tabs/ScrollbarSize.js
@@ -18,6 +18,17 @@ const styles = {
* It has been moved into the core in order to minimize the bundle size.
*/
class ScrollbarSize extends React.Component {
+ handleResize = debounce(() => {
+ const { onChange } = this.props;
+
+ const prevHeight = this.scrollbarHeight;
+ const prevWidth = this.scrollbarWidth;
+ this.setMeasurements();
+ if (prevHeight !== this.scrollbarHeight || prevWidth !== this.scrollbarWidth) {
+ onChange({ scrollbarHeight: this.scrollbarHeight, scrollbarWidth: this.scrollbarWidth });
+ }
+ }, 166); // Corresponds to 10 frames at 60 Hz.
+
componentDidMount() {
this.setMeasurements();
this.props.onLoad({
@@ -39,17 +50,6 @@ class ScrollbarSize extends React.Component {
this.scrollbarWidth = this.node.offsetWidth - this.node.clientWidth;
};
- handleResize = debounce(() => {
- const { onChange } = this.props;
-
- const prevHeight = this.scrollbarHeight;
- const prevWidth = this.scrollbarWidth;
- this.setMeasurements();
- if (prevHeight !== this.scrollbarHeight || prevWidth !== this.scrollbarWidth) {
- onChange({ scrollbarHeight: this.scrollbarHeight, scrollbarWidth: this.scrollbarWidth });
- }
- }, 166); // Corresponds to 10 frames at 60 Hz.
-
render() {
const { onChange } = this.props;
diff --git a/packages/material-ui/src/Tabs/Tabs.js b/packages/material-ui/src/Tabs/Tabs.js
index 39214efc861fbc..c689a90d8e572b 100644
--- a/packages/material-ui/src/Tabs/Tabs.js
+++ b/packages/material-ui/src/Tabs/Tabs.js
@@ -48,6 +48,19 @@ export const styles = theme => ({
});
class Tabs extends React.Component {
+ tabs = null;
+
+ valueToIndex = new Map();
+
+ handleResize = debounce(() => {
+ this.updateIndicatorState(this.props);
+ this.updateScrollButtonState();
+ }, 166); // Corresponds to 10 frames at 60 Hz.
+
+ handleTabsScroll = debounce(() => {
+ this.updateScrollButtonState();
+ }, 166); // Corresponds to 10 frames at 60 Hz.
+
state = {
indicatorStyle: {},
scrollerStyle: {
@@ -153,14 +166,6 @@ class Tabs extends React.Component {
return { tabsMeta, tabMeta };
};
- tabs = undefined;
- valueToIndex = new Map();
-
- handleResize = debounce(() => {
- this.updateIndicatorState(this.props);
- this.updateScrollButtonState();
- }, 166); // Corresponds to 10 frames at 60 Hz.
-
handleLeftScrollClick = () => {
if (this.tabs) {
this.moveTabsScroll(-this.tabs.clientWidth);
@@ -181,10 +186,6 @@ class Tabs extends React.Component {
});
};
- handleTabsScroll = debounce(() => {
- this.updateScrollButtonState();
- }, 166); // Corresponds to 10 frames at 60 Hz.
-
moveTabsScroll = delta => {
const { theme } = this.props;
@@ -197,36 +198,6 @@ class Tabs extends React.Component {
}
};
- updateIndicatorState(props) {
- const { theme, value } = props;
-
- const { tabsMeta, tabMeta } = this.getTabsMeta(value, theme.direction);
- let left = 0;
-
- if (tabMeta && tabsMeta) {
- const correction =
- theme.direction === 'rtl'
- ? tabsMeta.scrollLeftNormalized + tabsMeta.clientWidth - tabsMeta.scrollWidth
- : tabsMeta.scrollLeft;
- left = tabMeta.left - tabsMeta.left + correction;
- }
-
- const indicatorStyle = {
- left,
- // May be wrong until the font is loaded.
- width: tabMeta ? tabMeta.width : 0,
- };
-
- if (
- (indicatorStyle.left !== this.state.indicatorStyle.left ||
- indicatorStyle.width !== this.state.indicatorStyle.width) &&
- !isNaN(indicatorStyle.left) &&
- !isNaN(indicatorStyle.width)
- ) {
- this.setState({ indicatorStyle });
- }
- }
-
scrollSelectedIntoView = () => {
const { theme, value } = this.props;
const { tabsMeta, tabMeta } = this.getTabsMeta(value, theme.direction);
@@ -268,6 +239,36 @@ class Tabs extends React.Component {
}
};
+ updateIndicatorState(props) {
+ const { theme, value } = props;
+
+ const { tabsMeta, tabMeta } = this.getTabsMeta(value, theme.direction);
+ let left = 0;
+
+ if (tabMeta && tabsMeta) {
+ const correction =
+ theme.direction === 'rtl'
+ ? tabsMeta.scrollLeftNormalized + tabsMeta.clientWidth - tabsMeta.scrollWidth
+ : tabsMeta.scrollLeft;
+ left = tabMeta.left - tabsMeta.left + correction;
+ }
+
+ const indicatorStyle = {
+ left,
+ // May be wrong until the font is loaded.
+ width: tabMeta ? tabMeta.width : 0,
+ };
+
+ if (
+ (indicatorStyle.left !== this.state.indicatorStyle.left ||
+ indicatorStyle.width !== this.state.indicatorStyle.width) &&
+ !isNaN(indicatorStyle.left) &&
+ !isNaN(indicatorStyle.width)
+ ) {
+ this.setState({ indicatorStyle });
+ }
+ }
+
render() {
const {
action,
diff --git a/packages/material-ui/src/Tooltip/Tooltip.js b/packages/material-ui/src/Tooltip/Tooltip.js
index 6e7d1ede3dd6b5..23ad7057fefeb8 100644
--- a/packages/material-ui/src/Tooltip/Tooltip.js
+++ b/packages/material-ui/src/Tooltip/Tooltip.js
@@ -97,6 +97,28 @@ function flipPlacement(placement) {
}
class Tooltip extends React.Component {
+ enterTimer = null;
+
+ leaveTimer = null;
+
+ touchTimer = null;
+
+ closeTimer = null;
+
+ isControlled = null;
+
+ popper = null;
+
+ children = null;
+
+ ignoreNonTouchEvents = false;
+
+ handleResize = debounce(() => {
+ if (this.popper) {
+ this.popper._popper.scheduleUpdate();
+ }
+ }, 166); // Corresponds to 10 frames at 60 Hz.
+
constructor(props) {
super(props);
@@ -132,21 +154,6 @@ class Tooltip extends React.Component {
this.handleResize.clear();
}
- enterTimer = null;
- leaveTimer = null;
- touchTimer = null;
- closeTimer = null;
- isControlled = null;
- popper = null;
- children = null;
- ignoreNonTouchEvents = false;
-
- handleResize = debounce(() => {
- if (this.popper) {
- this.popper._popper.scheduleUpdate();
- }
- }, 166); // Corresponds to 10 frames at 60 Hz.
-
handleEnter = event => {
const { children, enterDelay } = this.props;
const childrenProps = children.props;
diff --git a/packages/material-ui/src/Tooltip/Tooltip.test.js b/packages/material-ui/src/Tooltip/Tooltip.test.js
index ce302b635cbb11..ceddcaaf58adba 100644
--- a/packages/material-ui/src/Tooltip/Tooltip.test.js
+++ b/packages/material-ui/src/Tooltip/Tooltip.test.js
@@ -140,7 +140,7 @@ describe('', () => {
it('should respond to external events', () => {
const wrapper = shallow(
-
+
,
);
const children = getTargetChildren(wrapper);
@@ -163,7 +163,7 @@ describe('', () => {
onOpen={handleRequestOpen}
onClose={handleClose}
>
-
+
,
);
const children = getTargetChildren(wrapper);
@@ -191,7 +191,7 @@ describe('', () => {
it('should not respond to quick events', () => {
const wrapper = shallow(
-
+
,
);
const children = getTargetChildren(wrapper);
@@ -205,7 +205,7 @@ describe('', () => {
it('should open on long press', () => {
const wrapper = shallow(
-
+
,
);
const children = getTargetChildren(wrapper);
@@ -224,7 +224,7 @@ describe('', () => {
it('should mount without any issue', () => {
mount(
-
+
,
);
});
@@ -244,7 +244,7 @@ describe('', () => {
it('should take the enterDelay into account', () => {
const wrapper = shallow(
-
+
,
);
const children = getTargetChildren(wrapper);
@@ -257,7 +257,7 @@ describe('', () => {
it('should take the leaveDelay into account', () => {
const wrapper = shallow(
-
+
,
);
const children = getTargetChildren(wrapper);
@@ -277,7 +277,9 @@ describe('', () => {
const handler = spy();
const wrapper = shallow(
-
+
,
);
const children = getTargetChildren(wrapper);
@@ -329,7 +331,9 @@ describe('', () => {
it('should raise a warning when we can listen to events', () => {
mount(
-
+
,
);
assert.strictEqual(consoleErrorMock.callCount(), 1, 'should call console.error');
diff --git a/packages/material-ui/src/internal/SwitchBase.js b/packages/material-ui/src/internal/SwitchBase.js
index 804d64a57e78f6..cd5e0565133bb0 100644
--- a/packages/material-ui/src/internal/SwitchBase.js
+++ b/packages/material-ui/src/internal/SwitchBase.js
@@ -32,6 +32,10 @@ export const styles = {
};
class SwitchBase extends React.Component {
+ input = null;
+
+ isControlled = null;
+
constructor(props) {
super(props);
@@ -44,9 +48,6 @@ class SwitchBase extends React.Component {
state = {};
- input = null;
- isControlled = null;
-
handleFocus = event => {
if (this.props.onFocus) {
this.props.onFocus(event);
diff --git a/packages/material-ui/src/styles/MuiThemeProvider.js b/packages/material-ui/src/styles/MuiThemeProvider.js
index 7a66597786cd9c..bd585729d0143e 100644
--- a/packages/material-ui/src/styles/MuiThemeProvider.js
+++ b/packages/material-ui/src/styles/MuiThemeProvider.js
@@ -11,6 +11,13 @@ import exactProp from '../utils/exactProp';
* This component should preferably be used at **the root of your component tree**.
*/
class MuiThemeProvider extends React.Component {
+ broadcast = createBroadcast();
+
+ unsubscribeId = null;
+
+ // We are not using the React state in order to avoid unnecessary rerender.
+ outerTheme = null;
+
constructor(props, context) {
super(props, context);
@@ -60,11 +67,6 @@ class MuiThemeProvider extends React.Component {
}
}
- broadcast = createBroadcast();
- unsubscribeId = null;
- // We are not using the React state in order to avoid unnecessary rerender.
- outerTheme = null;
-
// Simple merge between the outer theme and the local theme
mergeOuterLocalTheme(localTheme) {
// To support composition of theme.
diff --git a/packages/material-ui/src/styles/colorManipulator.js b/packages/material-ui/src/styles/colorManipulator.js
index c98935fe476694..68aa9a2fc9c22e 100644
--- a/packages/material-ui/src/styles/colorManipulator.js
+++ b/packages/material-ui/src/styles/colorManipulator.js
@@ -132,7 +132,7 @@ export function getLuminance(color: string) {
if (decomposedColor.type.indexOf('rgb') !== -1) {
const rgb = decomposedColor.values.map(val => {
val /= 255; // normalized
- return val <= 0.03928 ? val / 12.92 : Math.pow((val + 0.055) / 1.055, 2.4);
+ return val <= 0.03928 ? val / 12.92 : ((val + 0.055) / 1.055) ** 2.4;
});
// Truncate at 3 digits
return Number((0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2]).toFixed(3));
diff --git a/packages/material-ui/src/styles/createPalette.test.js b/packages/material-ui/src/styles/createPalette.test.js
index 4d353cd2dc12d8..ee90d0d3d38ac5 100644
--- a/packages/material-ui/src/styles/createPalette.test.js
+++ b/packages/material-ui/src/styles/createPalette.test.js
@@ -2,9 +2,9 @@
import { assert } from 'chai';
import consoleErrorMock from 'test/utils/consoleErrorMock';
-import createPalette, { dark, light } from './createPalette';
import { indigo, pink, deepOrange, green, red } from '../colors';
-import { lighten, darken } from '../styles/colorManipulator';
+import { lighten, darken } from './colorManipulator';
+import createPalette, { dark, light } from './createPalette';
describe('createPalette()', () => {
before(() => {
diff --git a/packages/material-ui/src/styles/withStyles.js b/packages/material-ui/src/styles/withStyles.js
index 6cae7524736507..c2b64c647d9a01 100644
--- a/packages/material-ui/src/styles/withStyles.js
+++ b/packages/material-ui/src/styles/withStyles.js
@@ -69,6 +69,20 @@ const withStyles = (stylesOrCreator, options = {}) => Component => {
);
class WithStyles extends React.Component {
+ disableStylesGeneration = false;
+
+ jss = null;
+
+ sheetOptions = null;
+
+ sheetsManager = sheetsManager;
+
+ stylesCreatorSaved = null;
+
+ theme = null;
+
+ unsubscribeId = null;
+
constructor(props, context) {
super(props, context);
@@ -259,14 +273,6 @@ const withStyles = (stylesOrCreator, options = {}) => Component => {
}
}
- disableStylesGeneration = false;
- jss = null;
- sheetOptions = null;
- sheetsManager = sheetsManager;
- stylesCreatorSaved = null;
- theme = null;
- unsubscribeId = null;
-
render() {
const { classes, innerRef, ...other } = this.props;
diff --git a/packages/material-ui/src/styles/withStyles.test.js b/packages/material-ui/src/styles/withStyles.test.js
index 83c769ba9478de..f0a263b588a0c4 100644
--- a/packages/material-ui/src/styles/withStyles.test.js
+++ b/packages/material-ui/src/styles/withStyles.test.js
@@ -14,7 +14,7 @@ import createGenerateClassName from './createGenerateClassName';
import { createShallow, createMount, getClasses } from '../test-utils';
// eslint-disable-next-line react/prefer-stateless-function
-class Empty extends React.Component<{ classes: Object, theme?: Object }> {
+class Empty extends React.Component<{}> {
render() {
return ;
}
diff --git a/packages/material-ui/src/styles/withTheme.js b/packages/material-ui/src/styles/withTheme.js
index 17591de6c3ebd4..bedd447f25fd11 100644
--- a/packages/material-ui/src/styles/withTheme.js
+++ b/packages/material-ui/src/styles/withTheme.js
@@ -18,6 +18,8 @@ function getDefaultTheme() {
// Provide the theme object as a property to the input component.
const withTheme = () => Component => {
class WithTheme extends React.Component {
+ unsubscribeId = null;
+
constructor(props, context) {
super(props, context);
@@ -41,8 +43,6 @@ const withTheme = () => Component => {
}
}
- unsubscribeId = null;
-
render() {
return ;
}
diff --git a/packages/material-ui/src/test-utils/until.test.js b/packages/material-ui/src/test-utils/until.test.js
index 2b98857365cc11..7cd99e3b73957d 100644
--- a/packages/material-ui/src/test-utils/until.test.js
+++ b/packages/material-ui/src/test-utils/until.test.js
@@ -102,8 +102,12 @@ describe('until', () => {
// eslint-disable-next-line react/no-multi-comp
class Bar extends React.Component<{}> {
static childContextTypes = { quux: PropTypes.bool };
+
getChildContext = () => ({ quux: true });
- render = () => ;
+
+ render() {
+ return ;
+ }
}
it('context propagation passes down context from an intermediary component', () => {
diff --git a/packages/material-ui/src/utils/ownerWindow.js b/packages/material-ui/src/utils/ownerWindow.js
index e40c3d828978b6..4cb952a4c1a3b7 100644
--- a/packages/material-ui/src/utils/ownerWindow.js
+++ b/packages/material-ui/src/utils/ownerWindow.js
@@ -1,6 +1,6 @@
// @flow
-import ownerDocument from '../utils/ownerDocument';
+import ownerDocument from './ownerDocument';
function ownerWindow(node: Node, fallback: window = window) {
const doc: Document = ownerDocument(node);
diff --git a/packages/material-ui/src/utils/reactHelpers.test.js b/packages/material-ui/src/utils/reactHelpers.test.js
index e7d58cf6fccd8c..14b92f80f3f00b 100644
--- a/packages/material-ui/src/utils/reactHelpers.test.js
+++ b/packages/material-ui/src/utils/reactHelpers.test.js
@@ -1,7 +1,7 @@
import React from 'react';
import { assert } from 'chai';
import { isMuiComponent, isMuiElement } from './reactHelpers';
-import { Input, ListItemAvatar, ListItemSecondaryAction, SvgIcon } from '../';
+import { Input, ListItemAvatar, ListItemSecondaryAction, SvgIcon } from '..';
describe('utils/reactHelpers.js', () => {
describe('isMuiElement', () => {
diff --git a/packages/material-ui/src/withWidth/withWidth.js b/packages/material-ui/src/withWidth/withWidth.js
index 380a0675d2f1d9..127c8b4f5a0487 100644
--- a/packages/material-ui/src/withWidth/withWidth.js
+++ b/packages/material-ui/src/withWidth/withWidth.js
@@ -35,6 +35,15 @@ const withWidth = (options = {}) => Component => {
} = options;
class WithWidth extends React.Component {
+ handleResize = debounce(() => {
+ const width = this.getWidth();
+ if (width !== this.state.width) {
+ this.setState({
+ width,
+ });
+ }
+ }, resizeInterval);
+
constructor(props) {
super(props);
@@ -88,15 +97,6 @@ const withWidth = (options = {}) => Component => {
return width;
}
- handleResize = debounce(() => {
- const width = this.getWidth();
- if (width !== this.state.width) {
- this.setState({
- width,
- });
- }
- }, resizeInterval);
-
render() {
const { initialWidth, theme, width, ...other } = this.props;
diff --git a/pages/api/popover.md b/pages/api/popover.md
index a0056cd09569c8..d48069bec32b10 100644
--- a/pages/api/popover.md
+++ b/pages/api/popover.md
@@ -15,7 +15,7 @@ filename: /packages/material-ui/src/Popover/Popover.js
| action | func | | This is callback property. It's called by the component on mount. This is useful when you want to trigger an action programmatically. It currently only supports updatePosition() action.
**Signature:** `function(actions: object) => void` *actions:* This object contains all posible actions that can be triggered programmatically. |
| anchorEl | union: object | func | | This is the DOM element, or a function that returns the DOM element, that may be used to set the position of the popover. |
| anchorOrigin | {horizontal?: union: number | enum: 'left' | 'center' | 'right'