From 1575d2f01db2b4e74f898f50cbd7c18254bbb5e4 Mon Sep 17 00:00:00 2001 From: "mark.ck" Date: Tue, 19 Feb 2019 19:03:06 +0800 Subject: [PATCH] feat(Transfer): support rtl prop --- src/transfer/view/transfer.jsx | 27 +++++++++++++++------------ test/transfer/index-spec.js | 8 +++++++- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/transfer/view/transfer.jsx b/src/transfer/view/transfer.jsx index 1568102883..0de3230fb7 100644 --- a/src/transfer/view/transfer.jsx +++ b/src/transfer/view/transfer.jsx @@ -134,7 +134,7 @@ class Transfer extends Component { /** * 自定义国际化文案对象 */ - locale: PropTypes.object + locale: PropTypes.object, }; static defaultProps = { @@ -159,18 +159,13 @@ class Transfer extends Component { }; loop(data.label); - if (labelString.length >= searchedValue.length && - labelString.indexOf(searchedValue) > -1) { - return true; - } - - return false; + return labelString.length >= searchedValue.length && + labelString.indexOf(searchedValue) > -1; }, onSearch: () => {}, notFoundContent: 'Not Found', titles: [], - // eslint-disable-next-line - operations: [, ], + operations: [], defaultLeftChecked: [], defaultRightChecked: [], sortable: false, @@ -181,8 +176,13 @@ class Transfer extends Component { constructor(props, context) { super(props, context); - const { value, defaultValue, defaultLeftChecked, defaultRightChecked, dataSource } = props; - + const { value, defaultValue, defaultLeftChecked, defaultRightChecked, dataSource, rtl, operations } = props; + if (operations.length === 0) { + const iconProp = rtl ? { dir: 'rtl'} : {}; + // eslint-disable-next-line + operations.push(); + operations.push(); + } const { left, right } = this.filterCheckedValue( this.normalizeValue(defaultLeftChecked), this.normalizeValue(defaultRightChecked), @@ -428,7 +428,7 @@ class Transfer extends Component { render() { const { prefix, mode, disabled, className, dataSource, locale, showSearch, filter, onSearch, leftDisabled, rightDisabled, searchPlaceholder, notFoundContent, titles, listClassName, - listStyle, itemRender, sortable } = this.props; + listStyle, itemRender, sortable, rtl } = this.props; const { value, leftCheckedValue, rightCheckedValue } = this.state; const itemValues = dataSource.map(item => item.value); const leftDatasource = this.groupDatasource(this.leftValue, itemValues, dataSource); @@ -453,6 +453,9 @@ class Transfer extends Component { }; const others = pickOthers(Object.keys(Transfer.propTypes), this.props); + if (rtl) { + others.dir = 'rtl'; + } return (
{ it('should render by defaultLeftChecked and defaultRightChecked', () => { wrapper = mount(); + defaultRightChecked={['1']} dataSource={dataSource} />); assert(findFooterCount(wrapper, 0) === '1/3'); assert(findFooterCheckbox(wrapper, 0).hasClass('indeterminate')); @@ -452,6 +452,12 @@ describe('Transfer', () => { }, 1000); }); + it('should support rtl prop', () => { + wrapper = mount(); + assert(wrapper.find('div').at(0).props().dir === 'rtl'); + + }); + it('should support sorting items', () => { let value, position, sortCalled; const handleSort = (v, p) => {