From 4d66fcaab4722167e0637469fb9e7e7f934ff4fc Mon Sep 17 00:00:00 2001 From: mark-ck Date: Mon, 28 Oct 2019 21:46:51 +0800 Subject: [PATCH 1/4] feat(Timeline): update lifecycle --- docs/timeline/demo/fold.md | 2 +- src/timeline/view/timeline.jsx | 17 ++++++++++++----- test/timeline/index-spec.js | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) 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/timeline/view/timeline.jsx b/src/timeline/view/timeline.jsx index 769bf42332..ada05e5ed3 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,17 @@ class Timeline extends Component { }; } - componentWillReceiveProps(nextProps) { - if ('fold' in nextProps) { - this.setState({ + static getDerivedStateFromProps(nextProps, prevState) { + if ( + 'fold' in nextProps && + 'fold' in prevState && + nextProps.fold.length !== prevState.fold.length + ) { + return { fold: nextProps.fold, - }); + }; } + return null; } toggleFold(folderIndex, total) { @@ -138,4 +145,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( From 4d0a15694f419c5cd900b424ee2fcd395b640dc7 Mon Sep 17 00:00:00 2001 From: myronliu347 Date: Wed, 20 Nov 2019 11:10:53 +0800 Subject: [PATCH 2/4] temp(Cascader): add change default indeterminate --- src/cascader/cascader.jsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cascader/cascader.jsx b/src/cascader/cascader.jsx index c0d5bfb70d..697b6d3b4f 100644 --- a/src/cascader/cascader.jsx +++ b/src/cascader/cascader.jsx @@ -731,9 +731,10 @@ export default class Cascader extends Component { props.checkable = !(canOnlyCheckLeaf && canExpand); props.checked = value.indexOf(item.value) > -1; 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 { From 4a12b265890f68be4c27a69b85304960b4276eee Mon Sep 17 00:00:00 2001 From: myronliu347 Date: Wed, 20 Nov 2019 11:15:20 +0800 Subject: [PATCH 3/4] temp(*): add cascader item checked --- src/cascader/cascader.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cascader/cascader.jsx b/src/cascader/cascader.jsx index 697b6d3b4f..e7cf74382e 100644 --- a/src/cascader/cascader.jsx +++ b/src/cascader/cascader.jsx @@ -729,7 +729,8 @@ 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 ? false From 4a0e29e5f233099ed17eb857fda497a9b344df42 Mon Sep 17 00:00:00 2001 From: mark-ck Date: Wed, 20 Nov 2019 14:44:34 +0800 Subject: [PATCH 4/4] feat(Timeline): update lifecycle --- src/timeline/view/timeline.jsx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/timeline/view/timeline.jsx b/src/timeline/view/timeline.jsx index ada05e5ed3..1a9b2f45ad 100644 --- a/src/timeline/view/timeline.jsx +++ b/src/timeline/view/timeline.jsx @@ -46,15 +46,21 @@ class Timeline extends Component { } static getDerivedStateFromProps(nextProps, prevState) { - if ( - 'fold' in nextProps && - 'fold' in prevState && - nextProps.fold.length !== prevState.fold.length - ) { + const { innerUpdate, fold } = prevState; + + if (innerUpdate) { + return { + fold, + innerUpdate: false, + }; + } + + if ('fold' in nextProps) { return { fold: nextProps.fold, }; } + return null; } @@ -73,7 +79,7 @@ class Timeline extends Component { } } - this.setState({ fold }); + this.setState({ fold, innerUpdate: true }); } }