From 2ed0d62fcf0f5b8ce166cb5a7f0fe9d5c85aae90 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Wed, 19 Sep 2018 13:14:46 +0800 Subject: [PATCH] fix: select option value support number 0 --- components/vc-menu/SubPopupMenu.jsx | 4 ++-- components/vc-menu/util.js | 2 +- components/vc-select/DropdownMenu.jsx | 2 +- components/vc-select/util.js | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/components/vc-menu/SubPopupMenu.jsx b/components/vc-menu/SubPopupMenu.jsx index 0bea756de..0109cf808 100644 --- a/components/vc-menu/SubPopupMenu.jsx +++ b/components/vc-menu/SubPopupMenu.jsx @@ -45,7 +45,7 @@ export function saveRef (key, c) { export function getActiveKey (props, originalActiveKey) { let activeKey = originalActiveKey const { eventKey, defaultActiveFirst, children } = props - if (activeKey) { + if (activeKey !== undefined && activeKey !== null) { let found loopMenuItem(children, (c, i) => { const propsData = c.componentOptions.propsData || {} @@ -205,7 +205,7 @@ const SubPopupMenu = { getEventKey () { // when eventKey not available ,it's menu and return menu id '0-menu-' - return this.eventKey || '0-menu-' + return this.eventKey !== undefined ? this.eventKey : '0-menu-' }, getOpenTransitionName () { diff --git a/components/vc-menu/util.js b/components/vc-menu/util.js index 61f4bf4f8..dc41512b8 100644 --- a/components/vc-menu/util.js +++ b/components/vc-menu/util.js @@ -3,7 +3,7 @@ export function noop () { export function getKeyFromChildrenIndex (child, menuEventKey, index) { const prefix = menuEventKey || '' - return child.key || `${prefix}item_${index}` + return child.key === undefined ? `${prefix}item_${index}` : child.key } export function getMenuIdFromSubMenuEventKey (eventKey) { diff --git a/components/vc-select/DropdownMenu.jsx b/components/vc-select/DropdownMenu.jsx index a009bf8fa..bd0ba0bb7 100644 --- a/components/vc-select/DropdownMenu.jsx +++ b/components/vc-select/DropdownMenu.jsx @@ -126,7 +126,7 @@ export default { let clonedMenuItems = menuItems if (selectedKeys.length || firstActiveValue) { if (props.visible && !this.lastVisible) { - activeKeyProps.activeKey = selectedKeys[0] || firstActiveValue + activeKeyProps.activeKey = selectedKeys[0] !== undefined ? selectedKeys[0] : firstActiveValue } let foundFirst = false // set firstActiveItem via cloning menus diff --git a/components/vc-select/util.js b/components/vc-select/util.js index 12253d135..1eb65d691 100644 --- a/components/vc-select/util.js +++ b/components/vc-select/util.js @@ -122,7 +122,7 @@ export function getSelectKeys (menuItems, value) { } else { const itemValue = getValuePropValue(item) const itemKey = item.key - if (findIndexInValueBySingleValue(value, itemValue) !== -1 && itemKey) { + if (findIndexInValueBySingleValue(value, itemValue) !== -1 && itemKey !== undefined) { selectedKeys.push(itemKey) } }