diff --git a/antdv-demo b/antdv-demo index c18fda17a..26019de23 160000 --- a/antdv-demo +++ b/antdv-demo @@ -1 +1 @@ -Subproject commit c18fda17a11855f340d0f74de1d2f7b8ef591888 +Subproject commit 26019de237561b0d68e22a4e46537ee8e2e6f0fe diff --git a/components/_util/props-util.js b/components/_util/props-util.js index 904cf5279..39a3536ac 100644 --- a/components/_util/props-util.js +++ b/components/_util/props-util.js @@ -124,7 +124,7 @@ const getSlotOptions = ele => { return componentOptions ? componentOptions.Ctor.options || {} : {}; }; const findDOMNode = instance => { - let node = instance.$el; + let node = instance.$el || instance; while (node && !node.tagName) { node = node.nextSibling; } @@ -271,7 +271,7 @@ const getKey = ele => { return key; }; -export function getEvents(ele, on = true) { +export function getEvents(ele = {}, on = true) { let props = {}; if (ele.$) { props = { ...props, ...ele.$attrs }; diff --git a/components/cascader/index.jsx b/components/cascader/index.jsx index 848df2dc9..bf354c4be 100644 --- a/components/cascader/index.jsx +++ b/components/cascader/index.jsx @@ -12,13 +12,12 @@ import RightOutlined from '@ant-design/icons-vue/RightOutlined'; import RedoOutlined from '@ant-design/icons-vue/RedoOutlined'; import { hasProp, - filterEmpty, getOptionProps, - getComponentFromProp, isValidElement, getComponent, splitAttrs, findDOMNode, + getSlot, } from '../_util/props-util'; import BaseMixin from '../_util/BaseMixin'; import { cloneElement } from '../_util/vnode'; @@ -279,7 +278,7 @@ const Cascader = { getLabel() { const { options } = this; const names = getFilledFieldNames(this.$props); - const displayRender = getComponent(this, 'displayRender') || defaultDisplayRender; + const displayRender = getComponent(this, 'displayRender', {}, false) || defaultDisplayRender; const value = this.sValue; const unwrappedValue = Array.isArray(value[0]) ? value[0] : value; const selectedOptions = arrayTreeFilter( @@ -374,10 +373,10 @@ const Cascader = { }, render() { - const { $slots, sPopupVisible, inputValue, configProvider, localeData } = this; + const { sPopupVisible, inputValue, configProvider, localeData } = this; const { sValue: value, inputFocused } = this.$data; const props = getOptionProps(this); - let suffixIcon = getComponentFromProp(this, 'suffixIcon'); + let suffixIcon = getComponent(this, 'suffixIcon'); suffixIcon = Array.isArray(suffixIcon) ? suffixIcon[0] : suffixIcon; const { getPopupContainer: getContextPopupContainer } = configProvider; const { @@ -494,7 +493,7 @@ const Cascader = { onKeydown: this.handleKeyDown, onChange: showSearch ? this.handleInputChange : noop, }; - const children = filterEmpty($slots.default); + const children = getSlot(this); const inputIcon = (suffixIcon && (isValidElement(suffixIcon) ? ( cloneElement(suffixIcon, { @@ -544,9 +543,4 @@ const Cascader = { }, }; -/* istanbul ignore next */ -Cascader.install = function(app) { - app.component(Cascader.name, Cascader); -}; - export default Cascader; diff --git a/components/vc-cascader/Cascader.jsx b/components/vc-cascader/Cascader.jsx index 0fcd9c175..ae8d73ae4 100644 --- a/components/vc-cascader/Cascader.jsx +++ b/components/vc-cascader/Cascader.jsx @@ -1,4 +1,4 @@ -import { getComponent, getListeners } from '../_util/props-util'; +import { getComponent, getSlot } from '../_util/props-util'; import PropTypes from '../_util/vue-types'; import Trigger from '../vc-trigger'; import Menus from './Menus'; @@ -92,7 +92,7 @@ export default { this.children = undefined; // warning(!('filedNames' in props), // '`filedNames` of Cascader is a typo usage and deprecated, please use `fieldNames` instead.'); - + this.defaultFieldNames = { label: 'label', value: 'value', children: 'children' }; return { sPopupVisible: popupVisible, sActiveValue: initialValue, @@ -327,7 +327,6 @@ export default { handlePopupVisibleChange, handleKeyDown, } = this; - const listeners = getListeners(this); const { prefixCls, transitionName, @@ -353,7 +352,6 @@ export default { visible: sPopupVisible, loadingIcon, expandIcon, - ...listeners, onSelect: handleMenuSelect, onItemDoubleClick: this.handleItemDoubleClick, }; @@ -376,7 +374,8 @@ export default { onPopupVisibleChange: handlePopupVisibleChange, ref: this.saveTrigger, }; - const children = this.children; + const children = getSlot(this); + this.children = children; return ( {children && diff --git a/components/vc-cascader/Menus.jsx b/components/vc-cascader/Menus.jsx index 80fce3641..ba40abbca 100644 --- a/components/vc-cascader/Menus.jsx +++ b/components/vc-cascader/Menus.jsx @@ -1,4 +1,4 @@ -import { getComponent } from '../_util/props-util'; +import { getComponent, findDOMNode } from '../_util/props-util'; import PropTypes from '../_util/vue-types'; import arrayTreeFilter from 'array-tree-filter'; import BaseMixin from '../_util/BaseMixin'; @@ -6,6 +6,7 @@ import BaseMixin from '../_util/BaseMixin'; export default { name: 'CascaderMenus', mixins: [BaseMixin], + inheritAttrs: false, props: { value: PropTypes.array.def([]), activeValue: PropTypes.array.def([]), @@ -55,16 +56,9 @@ export default { this.__emit('itemDoubleClick', option, menuIndex, e); }; const key = option[this.getFieldName('value')]; - const expandProps = { - attrs: { - role: 'menuitem', - }, - on: { - click: onSelect, - dblclick: onItemDoubleClick, - mousedown: e => e.preventDefault(), - }, - key: Array.isArray(key) ? key.join('__ant__') : key, + let expandProps = { + onClick: onSelect, + onDblclick: onItemDoubleClick, }; let menuItemCls = `${prefixCls}-menu-item`; let expandIconNode = null; @@ -77,15 +71,15 @@ export default { } } if (expandTrigger === 'hover' && (hasChildren || option.isLeaf === false)) { - expandProps.on = { - mouseenter: this.delayOnSelect.bind(this, onSelect), - mouseleave: this.delayOnSelect.bind(this), - click: onSelect, + expandProps = { + onMouseenter: this.delayOnSelect.bind(this, onSelect), + onMouseleave: this.delayOnSelect.bind(this), + onClick: onSelect, }; } if (this.isActiveOption(option, menuIndex)) { menuItemCls += ` ${prefixCls}-menu-item-active`; - expandProps.ref = this.getMenuItemRef(menuIndex); + expandProps.ref = this.saveMenuItem(menuIndex); } if (option.disabled) { menuItemCls += ` ${prefixCls}-menu-item-disabled`; @@ -101,10 +95,15 @@ export default { } else if (typeof option[this.getFieldName('label')] === 'string') { title = option[this.getFieldName('label')]; } - expandProps.attrs.title = title; - expandProps.class = menuItemCls; return ( -
  • +