feat: update rc-cascader to 0.17.1

pull/666/head
tangjinzhou 2019-02-18 22:13:29 +08:00
parent f2fba47e4d
commit 9e9339c3b3
4 changed files with 24 additions and 13 deletions

View File

@ -1,4 +1,4 @@
// based on rc-calendar 9.8.2
// based on rc-calendar 9.10.8
import Vue from 'vue';
import ref from 'vue-ref';
import Calendar from './src/';

View File

@ -5,7 +5,7 @@ import Menus from './Menus';
import KeyCode from '../_util/KeyCode';
import arrayTreeFilter from 'array-tree-filter';
import shallowEqualArrays from 'shallow-equal/arrays';
import { hasProp, getEvents } from '../_util/props-util';
import { hasProp, getEvents, getSlot } from '../_util/props-util';
import BaseMixin from '../_util/BaseMixin';
import { cloneElement } from '../_util/vnode';
@ -53,7 +53,7 @@ export default {
props: {
value: PropTypes.array,
defaultValue: PropTypes.array,
options: PropTypes.array.def([]).isRequired,
options: PropTypes.array,
// onChange: PropTypes.func,
// onPopupVisibleChange: PropTypes.func,
popupVisible: PropTypes.bool,
@ -96,12 +96,11 @@ export default {
if (!shallowEqualArrays(val, oldValue)) {
const newValues = {
sValue: val || [],
sActiveValue: val || [],
};
// allow activeValue diff from value
// https://github.com/ant-design/ant-design/issues/2767
if (hasProp(this, 'loadData')) {
delete newValues.sActiveValue;
if (!hasProp(this, 'loadData')) {
newValues.sActiveValue = val || [];
}
this.setState(newValues);
}
@ -124,7 +123,7 @@ export default {
return this.fieldNames;
},
getCurrentLevelOptions() {
const { options, sActiveValue = [] } = this;
const { options = [], sActiveValue = [] } = this;
const result = arrayTreeFilter(
options,
(o, level) => o[this.getFieldName('value')] === sActiveValue[level],
@ -137,7 +136,7 @@ export default {
},
getActiveOptions(activeValue) {
return arrayTreeFilter(
this.options,
this.options || [],
(o, level) => o[this.getFieldName('value')] === activeValue[level],
{ childrenKeyName: this.getFieldName('children') },
);
@ -214,6 +213,12 @@ export default {
}
this.setState(newState);
},
handleItemDoubleClick () {
const { changeOnSelect } = this.$props;
if (changeOnSelect) {
this.setPopupVisible(false);
}
},
handleKeyDown(e) {
const { $slots } = this;
const children = $slots.default && $slots.default[0];
@ -313,7 +318,7 @@ export default {
prefixCls,
transitionName,
popupClassName,
options,
options = [],
disabled,
builtinPlacements,
popupPlacement,
@ -338,6 +343,7 @@ export default {
on: {
...$listeners,
select: handleMenuSelect,
itemDoubleClick: this.handleItemDoubleClick
},
};
menus = <Menus {...menusProps} />;
@ -362,10 +368,11 @@ export default {
},
ref: 'trigger',
};
const children = getSlot(this, 'default')[0]
return (
<Trigger {...triggerProps}>
{$slots.default &&
cloneElement($slots.default[0], {
{children &&
cloneElement(children[0], {
on: {
keydown: handleKeyDown,
},

View File

@ -9,7 +9,7 @@ export default {
props: {
value: PropTypes.array.def([]),
activeValue: PropTypes.array.def([]),
options: PropTypes.array.isRequired,
options: PropTypes.array,
prefixCls: PropTypes.string.def('rc-cascader-menus'),
expandTrigger: PropTypes.string.def('click'),
// onSelect: PropTypes.func,
@ -51,11 +51,15 @@ export default {
const onSelect = e => {
this.__emit('select', option, menuIndex, e);
};
const onItemDoubleClick = e => {
this.__emit('itemDoubleClick', option, menuIndex, e);
};
const key = option[this.getFieldName('value')];
const expandProps = {
attrs: {},
on: {
click: onSelect,
doubleclick: onItemDoubleClick,
},
key: Array.isArray(key) ? key.join('__ant__') : key,
};

View File

@ -1,3 +1,3 @@
// based on rc-cascader 0.16.2
// based on rc-cascader 0.17.1
import Cascader from './Cascader';
export default Cascader;