diff --git a/docs/timeline/demo/fold.md b/docs/timeline/demo/fold.md index 38a04873d9..b8b75f4d2a 100644 --- a/docs/timeline/demo/fold.md +++ b/docs/timeline/demo/fold.md @@ -64,4 +64,4 @@ ReactDOM.render(, mountNode); margin-bottom: 20px; } -```` \ No newline at end of file +```` diff --git a/src/cascader/cascader.jsx b/src/cascader/cascader.jsx index c0d5bfb70d..e7cf74382e 100644 --- a/src/cascader/cascader.jsx +++ b/src/cascader/cascader.jsx @@ -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 { diff --git a/src/timeline/view/timeline.jsx b/src/timeline/view/timeline.jsx index 769bf42332..1a9b2f45ad 100644 --- a/src/timeline/view/timeline.jsx +++ b/src/timeline/view/timeline.jsx @@ -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'; @@ -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) { @@ -66,7 +79,7 @@ class Timeline extends Component { } } - this.setState({ fold }); + this.setState({ fold, innerUpdate: true }); } } @@ -138,4 +151,4 @@ class Timeline extends Component { } } -export default ConfigProvider.config(Timeline); +export default ConfigProvider.config(polyfill(Timeline)); diff --git a/test/timeline/index-spec.js b/test/timeline/index-spec.js index 07e2ec2e68..33a7431f75 100644 --- a/test/timeline/index-spec.js +++ b/test/timeline/index-spec.js @@ -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(