Skip to content

Commit

Permalink
Merge pull request #3108 from oliviertassinari/remove-deprecated-code
Browse files Browse the repository at this point in the history
[Core] Remove the deprecated API of v0.14.x
  • Loading branch information
oliviertassinari committed Feb 4, 2016
2 parents 66fcbfa + 501c16f commit 70b4e0f
Show file tree
Hide file tree
Showing 24 changed files with 26 additions and 2,026 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## HEAD

- Remove the deprecated API of `0.14.x`. (#3108)

## 0.14.4
###### _Feb 02, 2016_

Expand Down
2 changes: 1 addition & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The roadmap is a living document, and it is likely that priorities will change,
#### Breaking Changes

- [ ] Remove deprecated usage of JSON to generate children across the components.
- [ ] [[#3108](https://github.com/callemall/material-ui/pull/3108)] Remove deprecated components, methods & props.
- [x] [[#3108](https://github.com/callemall/material-ui/pull/3108)] Remove deprecated components, methods & props.
- [ ] [[#2957](https://github.com/callemall/material-ui/issues/2957)] Standardize callback signatures.
- [ ] [[#2980](https://github.com/callemall/material-ui/issues/2980)] [[#1839](https://github.com/callemall/material-ui/issues/1839)] Standardise Datepicker for ISO8601.

Expand Down
149 changes: 13 additions & 136 deletions src/DropDownMenu/DropDownMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ import React from 'react';
import Transitions from '../styles/transitions';
import DropDownArrow from '../svg-icons/navigation/arrow-drop-down';
import Menu from '../menus/menu';
import MenuItem from '../menus/menu-item';
import ClearFix from '../clearfix';
import getMuiTheme from '../styles/getMuiTheme';
import Popover from '../popover/popover';
import PopoverAnimationFromTop from '../popover/popover-animation-from-top';
import {mergeStyles, prepareStyles} from '../utils/styles';
import warning from 'warning';
import deprecated from '../utils/deprecatedPropType';

const DropDownMenu = React.createClass({

Expand Down Expand Up @@ -40,25 +37,11 @@ const DropDownMenu = React.createClass({
*/
disabled: React.PropTypes.bool,

/**
* `DropDownMenu` will use this member to display
* the name of the item.
*/
displayMember: deprecated(React.PropTypes.string,
'Instead, use composability.'),

/**
* Overrides the styles of icon element.
*/
iconStyle: React.PropTypes.object,

/**
* `DropDownMenu` will use this member to display
* the name of the item on the label.
*/
labelMember: deprecated(React.PropTypes.string,
'Instead, use composability.'),

/**
* Overrides the styles of label when the `DropDownMenu` is inactive.
*/
Expand All @@ -69,12 +52,6 @@ const DropDownMenu = React.createClass({
*/
maxHeight: React.PropTypes.number,

/**
* JSON data representing all menu items in the dropdown.
*/
menuItems: deprecated(React.PropTypes.array,
'Instead, use composability.'),

/**
* Overrides the styles of `Menu` when the `DropDownMenu` is displayed.
*/
Expand All @@ -90,12 +67,6 @@ const DropDownMenu = React.createClass({
*/
openImmediately: React.PropTypes.bool,

/**
* Index of the item selected.
*/
selectedIndex: deprecated(React.PropTypes.number,
'Use value instead to control the component.'),

/**
* Override the inline-styles of the root element.
*/
Expand All @@ -110,18 +81,6 @@ const DropDownMenu = React.createClass({
* The value that is currently selected.
*/
value: React.PropTypes.any,

/**
* Two-way binding link.
*/
valueLink: deprecated(React.PropTypes.object,
'It\'s deprecated by React too.'),

/**
* `DropDownMenu` will use this member as the value representing an item.
*/
valueMember: deprecated(React.PropTypes.string,
'Instead, use composability.'),
},

contextTypes: {
Expand All @@ -145,7 +104,6 @@ const DropDownMenu = React.createClass({
getInitialState() {
return {
open: this.props.openImmediately,
selectedIndex: this._isControlled() ? null : (this.props.selectedIndex || 0),
muiTheme: this.context.muiTheme || getMuiTheme(),
};
},
Expand All @@ -158,18 +116,14 @@ const DropDownMenu = React.createClass({

componentDidMount() {
if (this.props.autoWidth) this._setWidth();
if (this.props.hasOwnProperty('selectedIndex')) this._setSelectedIndex(this.props.selectedIndex);
},

componentWillReceiveProps(nextProps, nextContext) {
const newMuiTheme = nextContext.muiTheme ? nextContext.muiTheme : this.state.muiTheme;
this.setState({muiTheme: newMuiTheme});

if (this.props.autoWidth) this._setWidth();
if (nextProps.hasOwnProperty('value') || nextProps.hasOwnProperty('valueLink')) {
return;
} else if (nextProps.hasOwnProperty('selectedIndex')) {
this._setSelectedIndex(nextProps.selectedIndex);
if (this.props.autoWidth) {
this._setWidth();
}
},

Expand Down Expand Up @@ -235,10 +189,6 @@ const DropDownMenu = React.createClass({
*/
getInputNode() {
const root = this.refs.root;
const item = this.props.menuItems && this.props.menuItems[this.state.selectedIndex];
if (item) {
root.value = item[this.props.displayMember || 'text'];
}

root.focus = () => {
if (!this.props.disabled) {
Expand All @@ -260,11 +210,6 @@ const DropDownMenu = React.createClass({
}
},

_setSelectedIndex(index) {
warning(index >= 0, 'Cannot set selectedIndex to a negative index.');
this.setState({selectedIndex: (index >= 0) ? index : 0});
},

_onControlTouchTap(event) {
event.preventDefault();
if (!this.props.disabled) {
Expand All @@ -276,30 +221,9 @@ const DropDownMenu = React.createClass({
},

_onMenuItemTouchTap(key, payload, e) {
const {
onChange,
menuItems,
value,
valueLink,
valueMember,
} = this.props;

if (menuItems && (this.state.selectedIndex !== key || e.target.value !== value)) {
const selectedItem = menuItems[key];
if (selectedItem) {
e.target.value = selectedItem[valueMember || 'payload'];
}
this._onMenuRequestClose();
}

if (valueLink) {
valueLink.requestChange(e.target.value);
} else if (onChange) {
onChange(e, key, payload);
}
this.props.onChange(e, key, payload);

this.setState({
selectedIndex: key,
open: false,
});
},
Expand All @@ -311,27 +235,18 @@ const DropDownMenu = React.createClass({
});
},

_isControlled() {
return this.props.hasOwnProperty('value') ||
this.props.hasOwnProperty('valueLink');
},

render() {
const {
autoWidth,
children,
className,
displayMember,
iconStyle,
labelMember,
labelStyle,
maxHeight,
menuItems,
menuStyle,
style,
underlineStyle,
valueLink,
valueMember = 'payload',
value,
...other,
} = this.props;

Expand All @@ -343,57 +258,19 @@ const DropDownMenu = React.createClass({

const styles = this.getStyles();

let value;
let selectedIndex = this._isControlled() ? null : this.state.selectedIndex;

if (menuItems && typeof selectedIndex === 'number') {
warning(menuItems[selectedIndex],
`SelectedIndex of ${selectedIndex} does not exist in menuItems.`);
}

if (valueMember && this._isControlled()) {
value = this.props.hasOwnProperty('value') ? this.props.value : valueLink.value;
if (menuItems && value !== null && value !== undefined) {
for (let i = 0; i < menuItems.length; i++) {
if (menuItems[i][valueMember] === value) {
selectedIndex = i;
}
}
}
}

let displayValue = '';
if (menuItems) {
const selectedItem = menuItems[selectedIndex];
if (selectedItem) {
displayValue = selectedItem[labelMember || 'text'] || selectedItem[displayMember || 'text'];
React.Children.forEach(children, child => {
if (value === child.props.value) {
// This will need to be improved (in case primaryText is a node)
displayValue = child.props.label || child.props.primaryText;
}
} else {
React.Children.forEach(children, child => {
if (value === child.props.value) {
// This will need to be improved (in case primaryText is a node)
displayValue = child.props.label || child.props.primaryText;
}
});
}
});

let index = 0;
const menuItemElements = menuItems
? menuItems.map((item, idx) => (
<MenuItem
key={idx}
primaryText={item[displayMember || 'text']}
value={item[valueMember]}
onTouchTap={this._onMenuItemTouchTap.bind(this, idx, item)}
/>
))
: React.Children.map(children, child => {
const clone = React.cloneElement(child, {
onTouchTap: this._onMenuItemTouchTap.bind(this, index, child.props.value),
}, child.props.children);
index += 1;
return clone;
const menuItemElements = React.Children.map(children, (child, index) => {
return React.cloneElement(child, {
onTouchTap: this._onMenuItemTouchTap.bind(this, index, child.props.value),
});
});

let popoverStyle;
if (anchorEl && !autoWidth) {
Expand Down
20 changes: 0 additions & 20 deletions src/SelectField/SelectField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import TextField from '../text-field';
import DropDownMenu from '../DropDownMenu';
import getMuiTheme from '../styles/getMuiTheme';
import ContextPure from '../mixins/context-pure';
import deprecated from '../utils/deprecatedPropType';

const SelectField = React.createClass({

Expand Down Expand Up @@ -69,24 +68,11 @@ const SelectField = React.createClass({
*/
iconStyle: React.PropTypes.object,

/**
* `SelectField` will use text as default value,
* with this property you can choose another name.
*/
labelMember: deprecated(React.PropTypes.string,
'to promote composability.'),

/**
* Overrides the styles of label when the `SelectField` is inactive.
*/
labelStyle: React.PropTypes.object,

/**
* JSON data representing all menu items in the dropdown.
*/
menuItems: deprecated(React.PropTypes.array,
'to promote composability.'),

/**
* Callback function that is fired when the `SelectField` loses focus.
*/
Expand All @@ -107,12 +93,6 @@ const SelectField = React.createClass({
*/
selectFieldRoot: React.PropTypes.object, // Must be changed!

/**
* Index of the item selected.
*/
selectedIndex: deprecated(React.PropTypes.number,
'with menuItems.'),

/**
* Override the inline-styles of the root element.
*/
Expand Down
29 changes: 0 additions & 29 deletions src/TextField/TextField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import ContextPure from '../mixins/context-pure';
import TextFieldHint from './TextFieldHint';
import TextFieldLabel from './TextFieldLabel';
import TextFieldUnderline from './TextFieldUnderline';
import warning from 'warning';

/**
* Check if a value is valid to be displayed inside an input.
Expand Down Expand Up @@ -351,10 +350,6 @@ const TextField = React.createClass({
if (this.isMounted()) this._getInputNode().blur();
},

clearValue() {
this.setValue('');
},

focus() {
if (this.isMounted()) this._getInputNode().focus();
},
Expand All @@ -363,30 +358,6 @@ const TextField = React.createClass({
return this.isMounted() ? this._getInputNode().value : undefined;
},

setErrorText(newErrorText) {
warning(false, 'setErrorText() method is deprecated. Use the errorText property instead.');

if (this.isMounted()) {
this.setState({errorText: newErrorText});
}
},

setValue(newValue) {
warning(false,
`setValue() method is deprecated. Use the defaultValue property instead.
Or use the TextField as a controlled component with the value property.`);

if (this.isMounted()) {
if (this.props.multiLine) {
this.refs.input.setValue(newValue);
} else {
this._getInputNode().value = newValue;
}

this.setState({hasValue: isValid(newValue)});
}
},

_getInputNode() {
return (this.props.children || this.props.multiLine) ?
this.refs.input.getInputNode() : ReactDOM.findDOMNode(this.refs.input);
Expand Down
Loading

0 comments on commit 70b4e0f

Please sign in to comment.