diff --git a/components/popconfirm/__tests__/index.test.js b/components/popconfirm/__tests__/index.test.js
index 210679d0b..96ada5b63 100644
--- a/components/popconfirm/__tests__/index.test.js
+++ b/components/popconfirm/__tests__/index.test.js
@@ -5,6 +5,10 @@ function $$ (className) {
return document.body.querySelectorAll(className)
}
describe('Popconfirm', () => {
+ const eventObject = expect.objectContaining({
+ target: expect.anything(),
+ preventDefault: expect.any(Function),
+ })
it('should popup Popconfirm dialog', async () => {
const onVisibleChange = jest.fn()
@@ -29,12 +33,12 @@ describe('Popconfirm', () => {
triggerNode.trigger('click')
})
await asyncExpect(() => {
- expect(onVisibleChange).toBeCalledWith(true)
+ expect(onVisibleChange).toHaveBeenLastCalledWith(true, undefined)
expect($$('.popconfirm-test').length).toBe(1)
triggerNode.trigger('click')
}, 1000)
await asyncExpect(() => {
- expect(onVisibleChange).toBeCalledWith(false)
+ expect(onVisibleChange).toHaveBeenLastCalledWith(false, undefined)
})
})
diff --git a/components/popconfirm/index.jsx b/components/popconfirm/index.jsx
index 53cc2ca0d..cf44cde36 100644
--- a/components/popconfirm/index.jsx
+++ b/components/popconfirm/index.jsx
@@ -3,7 +3,7 @@ import omit from 'omit.js'
import Tooltip from '../tooltip'
import abstractTooltipProps from '../tooltip/abstractTooltipProps'
import PropTypes from '../_util/vue-types'
-import { getOptionProps, hasProp, getComponentFromProp } from '../_util/props-util'
+import { getOptionProps, hasProp, getComponentFromProp, mergeProps } from '../_util/props-util'
import BaseMixin from '../_util/BaseMixin'
import buttonTypes from '../button/buttonTypes'
import Icon from '../icon'
@@ -26,6 +26,8 @@ const Popconfirm = {
okText: PropTypes.any,
cancelText: PropTypes.any,
icon: PropTypes.any,
+ okButtonProps: PropTypes.object,
+ cancelButtonProps: PropTypes.object,
},
mixins: [BaseMixin],
model: {
@@ -38,18 +40,23 @@ const Popconfirm = {
},
},
data () {
- return {
- sVisible: this.$props.visible,
+ const props = getOptionProps(this)
+ const state = { sVisible: false }
+ if ('visible' in props) {
+ state.sVisible = props.visible
+ } else if ('defaultVisible' in props) {
+ state.sVisible = props.defaultVisible
}
+ return state
},
methods: {
onConfirm (e) {
- this.setVisible(false)
+ this.setVisible(false, e)
this.$emit('confirm', e)
},
onCancel (e) {
- this.setVisible(false)
+ this.setVisible(false, e)
this.$emit('cancel', e)
},
@@ -57,18 +64,35 @@ const Popconfirm = {
this.setVisible(sVisible)
},
- setVisible (sVisible) {
+ setVisible (sVisible, e) {
if (!hasProp(this, 'visible')) {
this.setState({ sVisible })
}
- this.$emit('visibleChange', sVisible)
+ this.$emit('visibleChange', sVisible, e)
},
getPopupDomNode () {
return this.$refs.tooltip.getPopupDomNode()
},
renderOverlay (popconfirmLocale) {
- const { prefixCls, okType } = this
- const icon = getComponentFromProp(this, 'icon') ||
+ const { prefixCls, okType, okButtonProps, cancelButtonProps } = this
+ const icon = getComponentFromProp(this, 'icon') ||
+ const cancelBtnProps = mergeProps({
+ props: {
+ size: 'small',
+ },
+ on: {
+ click: this.onCancel,
+ },
+ }, cancelButtonProps)
+ const okBtnProps = mergeProps({
+ props: {
+ type: okType,
+ size: 'small',
+ },
+ on: {
+ click: this.onConfirm,
+ },
+ }, okButtonProps)
return (
@@ -78,10 +102,10 @@ const Popconfirm = {
-
diff --git a/components/tooltip/Tooltip.jsx b/components/tooltip/Tooltip.jsx
index 246e114d5..7f1560fc0 100644
--- a/components/tooltip/Tooltip.jsx
+++ b/components/tooltip/Tooltip.jsx
@@ -61,25 +61,13 @@ export default {
})
},
- isHoverTrigger () {
- const { trigger } = this.$props
- if (!trigger || trigger === 'hover') {
- return true
- }
- if (Array.isArray(trigger)) {
- return trigger.indexOf('hover') >= 0
- }
- return false
- },
-
// Fix Tooltip won't hide at disabled button
// mouse events don't trigger at disabled button in Chrome
// https://github.com/react-component/tooltip/issues/18
getDisabledCompatibleChildren (ele) {
const isAntBtn = ele.componentOptions && ele.componentOptions.Ctor.options.__ANT_BUTTON
if (((isAntBtn && (ele.componentOptions.propsData.disabled || ele.componentOptions.propsData.disabled === '')) ||
- (ele.tag === 'button' && ele.data && ele.data.attrs.disabled !== false)) &&
- this.isHoverTrigger()) {
+ (ele.tag === 'button' && ele.data && ele.data.attrs.disabled !== false))) {
// Pick some layout related style properties up to span
// Prevent layout bugs like https://github.com/ant-design/ant-design/issues/5254
const { picked, omitted } = splitObject(
diff --git a/components/tooltip/__tests__/tooltip.test.js b/components/tooltip/__tests__/tooltip.test.js
index f104c0e9f..792846bbc 100644
--- a/components/tooltip/__tests__/tooltip.test.js
+++ b/components/tooltip/__tests__/tooltip.test.js
@@ -155,21 +155,6 @@ describe('Tooltip', () => {
// expect(wrapper2.find('span').at(0).element.style.display).toBe('block')
// })
- // it('should not wrap span when trigger is not hover', () => {
- // const wrapper = mount(
- //
- // Hello world!
- //
- // )
-
- // expect(wrapper.find('span')).toHaveLength(0)
- // })
-
// it('should works for arrowPointAtCenter', () => {
// const arrowWidth = 5
// const horizontalArrowShift = 16
diff --git a/components/tooltip/abstractTooltipProps.js b/components/tooltip/abstractTooltipProps.js
index a963cf614..1d74dd960 100644
--- a/components/tooltip/abstractTooltipProps.js
+++ b/components/tooltip/abstractTooltipProps.js
@@ -3,6 +3,7 @@ const triggerType = PropTypes.oneOf(['hover', 'focus', 'click', 'contextmenu'])
export default () => ({
trigger: PropTypes.oneOfType([triggerType, PropTypes.arrayOf(triggerType)]).def('hover'),
visible: PropTypes.bool,
+ defaultVisible: PropTypes.bool,
placement: PropTypes.oneOf(['top', 'left', 'right', 'bottom',
'topLeft', 'topRight', 'bottomLeft', 'bottomRight',
'leftTop', 'leftBottom', 'rightTop', 'rightBottom']).def('top'),
diff --git a/components/tooltip/placements.js b/components/tooltip/placements.js
index 6322c4a24..a3dcff89c 100644
--- a/components/tooltip/placements.js
+++ b/components/tooltip/placements.js
@@ -83,6 +83,7 @@ export default function getPlacements (config) {
...rcPlacements[key],
overflow: getOverflowOptions(autoAdjustOverflow),
}
+ placementMap[key].ignoreShake = true
})
return placementMap
}