Skip to content

Commit

Permalink
fix(Timeline): update lifecycle (#1276)
Browse files Browse the repository at this point in the history
* fix(Timeline): update lifecycle
  • Loading branch information
jinchanz authored and youluna committed Nov 20, 2019
1 parent 42de085 commit eb4ec42
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/timeline/demo/fold.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ ReactDOM.render(<Demo />, mountNode);
margin-bottom: 20px;
}

````
````
8 changes: 5 additions & 3 deletions src/cascader/cascader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -729,11 +729,13 @@ export default class Cascader extends Component {

if (multiple) {
props.checkable = !(canOnlyCheckLeaf && canExpand);
props.checked = value.indexOf(item.value) > -1;
props.checked =
value.indexOf(item.value) > -1 || !!item.checked;
props.indeterminate =
checkStrictly || canOnlyCheckLeaf
(checkStrictly || canOnlyCheckLeaf
? false
: this.indeterminate.indexOf(item.value) > -1;
: this.indeterminate.indexOf(item.value) >
-1) || !!item.indeterminate;
props.checkboxDisabled = !!item.checkboxDisabled;
props.onCheck = this.handleCheck.bind(this, item.value);
} else {
Expand Down
23 changes: 18 additions & 5 deletions src/timeline/view/timeline.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { Component, Children } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { polyfill } from 'react-lifecycles-compat';

import { obj } from '../../util';
import ConfigProvider from '../../config-provider';
import nextLocale from '../../locale/zh-cn';
Expand Down Expand Up @@ -43,12 +45,23 @@ class Timeline extends Component {
};
}

componentWillReceiveProps(nextProps) {
static getDerivedStateFromProps(nextProps, prevState) {
const { innerUpdate, fold } = prevState;

if (innerUpdate) {
return {
fold,
innerUpdate: false,
};
}

if ('fold' in nextProps) {
this.setState({
return {
fold: nextProps.fold,
});
};
}

return null;
}

toggleFold(folderIndex, total) {
Expand All @@ -66,7 +79,7 @@ class Timeline extends Component {
}
}

this.setState({ fold });
this.setState({ fold, innerUpdate: true });
}
}

Expand Down Expand Up @@ -138,4 +151,4 @@ class Timeline extends Component {
}
}

export default ConfigProvider.config(Timeline);
export default ConfigProvider.config(polyfill(Timeline));
2 changes: 1 addition & 1 deletion test/timeline/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Enzyme.configure({ adapter: new Adapter() });
const Item = Timeline.Item;

/* eslint-disable */
describe('Button', () => {
describe('Timeline', () => {
describe('render', () => {
it('should render a timeline', () => {
const wrapper = mount(
Expand Down

0 comments on commit eb4ec42

Please sign in to comment.