From 8e45a5e89b943e178b932e85be6b9e3a21d8097c Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sun, 22 Jul 2018 14:25:51 +0200 Subject: [PATCH] [core] Rename node to ref --- docs/src/modules/components/AppSearch.js | 10 ++-- .../pages/demos/dialogs/ConfirmationDialog.js | 8 +-- .../pages/utils/popper/ScrollPlayground.js | 10 ++-- docs/src/pages/utils/portal/SimplePortal.js | 4 +- packages/material-ui-lab/src/Slider/Slider.js | 14 +++--- .../src/SpeedDial/SpeedDial.js | 14 +++--- packages/material-ui/src/Chip/Chip.js | 4 +- packages/material-ui/src/Collapse/Collapse.js | 10 ++-- .../material-ui/src/Collapse/Collapse.test.js | 10 ++-- packages/material-ui/src/Input/Input.js | 22 ++++---- packages/material-ui/src/Input/Input.test.js | 14 +++--- packages/material-ui/src/Input/Textarea.js | 34 ++++++------- .../material-ui/src/Input/Textarea.test.js | 50 +++++++++---------- packages/material-ui/src/Menu/Menu.js | 20 ++++---- packages/material-ui/src/Menu/Menu.test.js | 16 +++--- packages/material-ui/src/MenuList/MenuList.js | 32 ++++++------ packages/material-ui/src/Modal/Modal.js | 12 ++--- packages/material-ui/src/Popover/Popover.js | 10 ++-- .../material-ui/src/Portal/Portal.test.js | 12 ++--- .../material-ui/src/RootRef/RootRef.test.js | 2 +- .../material-ui/src/Select/SelectInput.js | 26 +++++----- .../src/Select/SelectInput.test.js | 4 +- packages/material-ui/src/Slide/Slide.js | 16 +++--- packages/material-ui/src/Slide/Slide.test.js | 8 ++- packages/material-ui/src/Tab/Tab.js | 8 +-- packages/material-ui/src/Tab/Tab.test.js | 4 +- .../material-ui/src/Tabs/ScrollbarSize.js | 18 ++++--- .../src/Tabs/ScrollbarSize.test.js | 2 +- packages/material-ui/src/Tabs/Tabs.js | 44 ++++++++-------- packages/material-ui/src/Tabs/Tabs.test.js | 12 ++--- packages/material-ui/src/Tooltip/Tooltip.js | 4 +- .../material-ui/test/integration/Menu.test.js | 4 +- 32 files changed, 227 insertions(+), 231 deletions(-) diff --git a/docs/src/modules/components/AppSearch.js b/docs/src/modules/components/AppSearch.js index beceae5af8ad28..778adc7f78caea 100644 --- a/docs/src/modules/components/AppSearch.js +++ b/docs/src/modules/components/AppSearch.js @@ -153,16 +153,16 @@ const styles = theme => ({ }); class AppSearch extends React.Component { - input = null; + inputRef = null; handleKeyDown = event => { if ( ['/', 's'].indexOf(keycode(event)) !== -1 && document.activeElement.nodeName.toLowerCase() === 'body' && - document.activeElement !== this.input + document.activeElement !== this.inputRef ) { event.preventDefault(); - this.input.focus(); + this.inputRef.focus(); } }; @@ -181,8 +181,8 @@ class AppSearch extends React.Component { { - this.input = node; + ref={ref => { + this.inputRef = ref; }} className={classes.input} /> diff --git a/docs/src/pages/demos/dialogs/ConfirmationDialog.js b/docs/src/pages/demos/dialogs/ConfirmationDialog.js index 444e9fbdf5174b..242f5583e7f1d2 100644 --- a/docs/src/pages/demos/dialogs/ConfirmationDialog.js +++ b/docs/src/pages/demos/dialogs/ConfirmationDialog.js @@ -33,7 +33,7 @@ const options = [ ]; class ConfirmationDialogRaw extends React.Component { - radioGroup = null; + radioGroupRef = null; constructor(props) { super(props); @@ -51,7 +51,7 @@ class ConfirmationDialogRaw extends React.Component { } handleEntering = () => { - this.radioGroup.focus(); + this.radioGroupRef.focus(); }; handleCancel = () => { @@ -81,8 +81,8 @@ class ConfirmationDialogRaw extends React.Component { Phone Ringtone { - this.radioGroup = node; + ref={ref => { + this.radioGroupRef = ref; }} aria-label="Ringtone" name="ringtone" diff --git a/docs/src/pages/utils/popper/ScrollPlayground.js b/docs/src/pages/utils/popper/ScrollPlayground.js index 3b03e1c7f94988..a134cffca71d0b 100644 --- a/docs/src/pages/utils/popper/ScrollPlayground.js +++ b/docs/src/pages/utils/popper/ScrollPlayground.js @@ -140,14 +140,14 @@ class AnchorPlayground extends React.Component { }); }; - centerScroll = node => { - if (!node) { + centerScroll = ref => { + if (!ref) { return; } - const container = node.parentElement; - container.scrollTop = node.clientHeight / 4; - container.scrollLeft = node.clientWidth / 4; + const container = ref.parentElement; + container.scrollTop = ref.clientHeight / 4; + container.scrollLeft = ref.clientWidth / 4; }; render() { diff --git a/docs/src/pages/utils/portal/SimplePortal.js b/docs/src/pages/utils/portal/SimplePortal.js index c08f64d0929b5d..40c0056df15595 100644 --- a/docs/src/pages/utils/portal/SimplePortal.js +++ b/docs/src/pages/utils/portal/SimplePortal.js @@ -41,8 +41,8 @@ class SimplePortal extends React.Component {
{ - this.container = node; + ref={ref => { + this.container = ref; }} />
diff --git a/packages/material-ui-lab/src/Slider/Slider.js b/packages/material-ui-lab/src/Slider/Slider.js index af0861b7f537bf..5edd623ef48c41 100644 --- a/packages/material-ui-lab/src/Slider/Slider.js +++ b/packages/material-ui-lab/src/Slider/Slider.js @@ -222,13 +222,13 @@ class Slider extends React.Component { state = { currentState: 'initial' }; componentDidMount() { - if (this.container) { - this.container.addEventListener('touchstart', preventPageScrolling, { passive: false }); + if (this.containerRef) { + this.containerRef.addEventListener('touchstart', preventPageScrolling, { passive: false }); } } componentWillUnmount() { - this.container.removeEventListener('touchstart', preventPageScrolling, { passive: false }); + this.containerRef.removeEventListener('touchstart', preventPageScrolling, { passive: false }); } static getDerivedStateFromProps(nextProps, prevState) { @@ -292,7 +292,7 @@ class Slider extends React.Component { handleClick = event => { const { min, max, vertical, reverse } = this.props; - const percent = calculatePercent(this.container, event, vertical, reverse); + const percent = calculatePercent(this.containerRef, event, vertical, reverse); const value = percentToValue(percent, min, max); this.emitChange(event, value, () => { @@ -341,7 +341,7 @@ class Slider extends React.Component { handleMouseMove = event => { const { min, max, vertical, reverse } = this.props; - const percent = calculatePercent(this.container, event, vertical, reverse); + const percent = calculatePercent(this.containerRef, event, vertical, reverse); const value = percentToValue(percent, min, max); this.emitChange(event, value); @@ -471,8 +471,8 @@ class Slider extends React.Component { onMouseDown={this.handleMouseDown} onTouchStartCapture={this.handleTouchStart} onTouchMove={this.handleMouseMove} - ref={node => { - this.container = findDOMNode(node); + ref={ref => { + this.containerRef = findDOMNode(ref); }} {...other} > diff --git a/packages/material-ui-lab/src/SpeedDial/SpeedDial.js b/packages/material-ui-lab/src/SpeedDial/SpeedDial.js index b9e89f39a58cb5..b1697a34f07faf 100644 --- a/packages/material-ui-lab/src/SpeedDial/SpeedDial.js +++ b/packages/material-ui-lab/src/SpeedDial/SpeedDial.js @@ -36,8 +36,8 @@ class SpeedDial extends React.Component { }; handleKeyDown = event => { - const actions = ReactDOM.findDOMNode(this.actions); - const fab = ReactDOM.findDOMNode(this.fab); + const actions = ReactDOM.findDOMNode(this.actionsRef); + const fab = ReactDOM.findDOMNode(this.fabRef); const key = keycode(event); const currentFocus = document.activeElement; const { open, onClose, onKeyDown } = this.props; @@ -68,7 +68,7 @@ class SpeedDial extends React.Component { if (currentFocus.parentElement.previousElementSibling) { currentFocus.parentElement.previousElementSibling.firstChild.focus(); } else { - ReactDOM.findDOMNode(this.fab).focus(); + fab.focus(); } // Select the next action } else if (key === nextKey) { @@ -168,8 +168,8 @@ class SpeedDial extends React.Component { aria-haspopup="true" aria-expanded={open ? 'true' : 'false'} aria-controls={`${id}-actions`} - ref={node => { - this.fab = node; + ref={ref => { + this.fabRef = ref; }} {...ButtonProps} > @@ -179,8 +179,8 @@ class SpeedDial extends React.Component {
{ - this.actions = node; + ref={ref => { + this.actionsRef = ref; }} > {children} diff --git a/packages/material-ui/src/Chip/Chip.js b/packages/material-ui/src/Chip/Chip.js index bcfd8189df53d8..652f09be5d2b0c 100644 --- a/packages/material-ui/src/Chip/Chip.js +++ b/packages/material-ui/src/Chip/Chip.js @@ -192,8 +192,8 @@ class Chip extends React.Component { tabIndex={tabIndex} onClick={onClick} onKeyDown={this.handleKeyDown} - ref={node => { - this.chipRef = node; + ref={ref => { + this.chipRef = ref; }} {...other} > diff --git a/packages/material-ui/src/Collapse/Collapse.js b/packages/material-ui/src/Collapse/Collapse.js index f8c182e467a46e..74ce166b0aee4b 100644 --- a/packages/material-ui/src/Collapse/Collapse.js +++ b/packages/material-ui/src/Collapse/Collapse.js @@ -56,7 +56,7 @@ class Collapse extends React.Component { handleEntering = node => { const { timeout, theme } = this.props; - const wrapperHeight = this.wrapper ? this.wrapper.clientHeight : 0; + const wrapperHeight = this.wrapperRef ? this.wrapperRef.clientHeight : 0; const { duration: transitionDuration } = getTransitionProps(this.props, { mode: 'enter', @@ -87,7 +87,7 @@ class Collapse extends React.Component { }; handleExit = node => { - const wrapperHeight = this.wrapper ? this.wrapper.clientHeight : 0; + const wrapperHeight = this.wrapperRef ? this.wrapperRef.clientHeight : 0; node.style.height = `${wrapperHeight}px`; if (this.props.onExit) { @@ -97,7 +97,7 @@ class Collapse extends React.Component { handleExiting = node => { const { timeout, theme } = this.props; - const wrapperHeight = this.wrapper ? this.wrapper.clientHeight : 0; + const wrapperHeight = this.wrapperRef ? this.wrapperRef.clientHeight : 0; const { duration: transitionDuration } = getTransitionProps(this.props, { mode: 'exit', @@ -172,8 +172,8 @@ class Collapse extends React.Component { >
{ - this.wrapper = node; + ref={ref => { + this.wrapperRef = ref; }} >
{children}
diff --git a/packages/material-ui/src/Collapse/Collapse.test.js b/packages/material-ui/src/Collapse/Collapse.test.js index 1a07bf8ca22b51..3469ce8ccf1967 100644 --- a/packages/material-ui/src/Collapse/Collapse.test.js +++ b/packages/material-ui/src/Collapse/Collapse.test.js @@ -164,7 +164,7 @@ describe('', () => { }); it('no wrapper', () => { - instance.wrapper = false; + instance.wrapperRef = false; instance.handleEntering(element); assert.strictEqual( element.style.transitionDuration, @@ -174,7 +174,7 @@ describe('', () => { it('has wrapper', () => { const clientHeightMock = 10; - instance.wrapper = { clientHeight: clientHeightMock }; + instance.wrapperRef = { clientHeight: clientHeightMock }; instance.handleEntering(element); assert.strictEqual( element.style.transitionDuration, @@ -232,7 +232,7 @@ describe('', () => { describe('handleExit()', () => { it('should set height to the wrapper height', () => { const element = { style: { height: 'auto' } }; - instance.wrapper = { clientHeight: 666 }; + instance.wrapperRef = { clientHeight: 666 }; instance.handleExit(element); assert.strictEqual(element.style.height, '666px', 'should have 666px height'); }); @@ -278,7 +278,7 @@ describe('', () => { }); it('no wrapper', () => { - instance.wrapper = false; + instance.wrapperRef = false; instance.handleExiting(element); assert.strictEqual( element.style.transitionDuration, @@ -288,7 +288,7 @@ describe('', () => { it('has wrapper', () => { const clientHeightMock = 10; - instance.wrapper = { clientHeight: clientHeightMock }; + instance.wrapperRef = { clientHeight: clientHeightMock }; instance.handleExiting(element); assert.strictEqual( element.style.transitionDuration, diff --git a/packages/material-ui/src/Input/Input.js b/packages/material-ui/src/Input/Input.js index eb5c7dbb9c9be5..facb5c4d849089 100644 --- a/packages/material-ui/src/Input/Input.js +++ b/packages/material-ui/src/Input/Input.js @@ -292,7 +292,7 @@ class Input extends React.Component { componentDidMount() { if (!this.isControlled) { - this.checkDirty(this.input); + this.checkDirty(this.inputRef); } } @@ -335,7 +335,7 @@ class Input extends React.Component { handleChange = event => { if (!this.isControlled) { - this.checkDirty(this.input); + this.checkDirty(this.inputRef); } // Perform in the willUpdate @@ -344,22 +344,22 @@ class Input extends React.Component { } }; - handleRefInput = node => { - this.input = node; + handleRefInput = ref => { + this.inputRef = ref; - let ref; + let refProp; if (this.props.inputRef) { - ref = this.props.inputRef; + refProp = this.props.inputRef; } else if (this.props.inputProps && this.props.inputProps.ref) { - ref = this.props.inputProps.ref; + refProp = this.props.inputProps.ref; } - if (ref) { - if (typeof ref === 'function') { - ref(node); + if (refProp) { + if (typeof refProp === 'function') { + refProp(ref); } else { - ref.current = node; + refProp.current = ref; } } }; diff --git a/packages/material-ui/src/Input/Input.test.js b/packages/material-ui/src/Input/Input.test.js index 485faf4bb91c1f..30d9a12ffef800 100644 --- a/packages/material-ui/src/Input/Input.test.js +++ b/packages/material-ui/src/Input/Input.test.js @@ -231,7 +231,7 @@ describe('', () => { it('should fire the onFilled callback when dirtied', () => { assert.strictEqual(handleFilled.callCount, 1, 'should not have called the onFilled cb yet'); - wrapper.instance().input.value = 'hello'; + wrapper.instance().inputRef.value = 'hello'; wrapper.find('input').simulate('change'); assert.strictEqual(handleFilled.callCount, 2, 'should have called the onFilled cb'); }); @@ -239,7 +239,7 @@ describe('', () => { it('should fire the onEmpty callback when cleaned', () => { // Because of shallow() this hasn't fired since there is no mounting assert.strictEqual(handleEmpty.callCount, 0, 'should not have called the onEmpty cb yet'); - wrapper.instance().input.value = ''; + wrapper.instance().inputRef.value = ''; wrapper.find('input').simulate('change'); assert.strictEqual(handleEmpty.callCount, 1, 'should have called the onEmpty cb'); }); @@ -265,7 +265,7 @@ describe('', () => { describe('callbacks', () => { beforeEach(() => { - wrapper.instance().input = { value: '' }; + wrapper.instance().inputRef = { value: '' }; setFormControlContext({ onFilled: spy(), onEmpty: spy(), @@ -280,7 +280,7 @@ describe('', () => { onFilled: handleFilled, }); - wrapper.instance().input.value = 'hello'; + wrapper.instance().inputRef.value = 'hello'; wrapper.find('input').simulate('change'); assert.strictEqual(handleFilled.callCount, 1, 'should have called the onFilled props cb'); assert.strictEqual( @@ -296,7 +296,7 @@ describe('', () => { onEmpty: handleEmpty, }); - wrapper.instance().input.value = ''; + wrapper.instance().inputRef.value = ''; wrapper.find('input').simulate('change'); assert.strictEqual(handleEmpty.callCount, 1, 'should have called the onEmpty props cb'); assert.strictEqual( @@ -401,9 +401,9 @@ describe('', () => { it('should call checkDirty with input value', () => { instance.isControlled = false; - instance.input = 'woofinput'; + instance.inputRef = 'woofinput'; instance.componentDidMount(); - assert.strictEqual(instance.checkDirty.calledWith(instance.input), true); + assert.strictEqual(instance.checkDirty.calledWith(instance.inputRef), true); }); it('should call or not call checkDirty consistently', () => { diff --git a/packages/material-ui/src/Input/Textarea.js b/packages/material-ui/src/Input/Textarea.js index de6a8a8ad82fc5..60b26ebf59096a 100644 --- a/packages/material-ui/src/Input/Textarea.js +++ b/packages/material-ui/src/Input/Textarea.js @@ -43,11 +43,11 @@ export const styles = { * @ignore - internal component. */ class Textarea extends React.Component { - shadow = null; + shadowRef = null; - singlelineShadow = null; + singlelineShadowRef = null; - input = null; + inputRef = null; value = null; @@ -82,33 +82,33 @@ class Textarea extends React.Component { this.handleResize.clear(); } - handleRefInput = node => { - this.input = node; + handleRefInput = ref => { + this.inputRef = ref; const { textareaRef } = this.props; if (textareaRef) { if (typeof textareaRef === 'function') { - textareaRef(node); + textareaRef(ref); } else { - textareaRef.current = node; + textareaRef.current = ref; } } }; - handleRefSinglelineShadow = node => { - this.singlelineShadow = node; + handleRefSinglelineShadow = ref => { + this.singlelineShadowRef = ref; }; - handleRefShadow = node => { - this.shadow = node; + handleRefShadow = ref => { + this.shadowRef = ref; }; handleChange = event => { this.value = event.target.value; - if (typeof this.props.value === 'undefined' && this.shadow) { + if (typeof this.props.value === 'undefined' && this.shadowRef) { // The component is not controlled, we need to update the shallow value. - this.shadow.value = this.value; + this.shadowRef.value = this.value; this.syncHeightWithShadow(); } @@ -119,17 +119,17 @@ class Textarea extends React.Component { syncHeightWithShadow() { const props = this.props; - if (!this.shadow || !this.singlelineShadow) { + if (!this.shadowRef || !this.singlelineShadowRef) { return; } // The component is controlled, we need to update the shallow value. if (typeof props.value !== 'undefined') { - this.shadow.value = props.value == null ? '' : String(props.value); + this.shadowRef.value = props.value == null ? '' : String(props.value); } - const lineHeight = this.singlelineShadow.scrollHeight; - let newHeight = this.shadow.scrollHeight; + const lineHeight = this.singlelineShadowRef.scrollHeight; + let newHeight = this.shadowRef.scrollHeight; // Guarding for jsdom, where scrollHeight isn't present. // See https://github.com/tmpvar/jsdom/issues/1013 diff --git a/packages/material-ui/src/Input/Textarea.test.js b/packages/material-ui/src/Input/Textarea.test.js index 6e6f6a4023b630..03262f5a67c5da 100644 --- a/packages/material-ui/src/Input/Textarea.test.js +++ b/packages/material-ui/src/Input/Textarea.test.js @@ -7,17 +7,17 @@ import Textarea from './Textarea'; function assignRefs(wrapper) { // refs don't work with shallow renders in enzyme so here we directly define // 'this.input', 'this.shadow', etc. for this Textarea via wrapper.instance() - const input = wrapper.find('textarea').last(); - wrapper.instance().input = input; - const textareaShadow = wrapper.find('textarea').at(2); - wrapper.instance().shadow = textareaShadow; - const singlelineShadow = wrapper.find('textarea').first(); - wrapper.instance().singlelineShadow = singlelineShadow; + const inputRef = wrapper.find('textarea').last(); + wrapper.instance().inputRef = inputRef; + const textareaShadowRef = wrapper.find('textarea').at(2); + wrapper.instance().shadowRef = textareaShadowRef; + const singlelineShadowRef = wrapper.find('textarea').first(); + wrapper.instance().singlelineShadowRef = singlelineShadowRef; return { - singlelineShadow, - textareaShadow, - input, + inputRef, + singlelineShadowRef, + textareaShadowRef, }; } @@ -47,15 +47,15 @@ describe('