feat: update tooltip

pull/1845/head
tangjinzhou 2020-02-26 20:20:35 +08:00
parent 05658b7165
commit ab8768b19b
6 changed files with 27 additions and 17 deletions

View File

@ -1,5 +1,5 @@
module.exports = { module.exports = {
dev: { dev: {
componentName: 'tag', // dev components componentName: 'tooltip', // dev components
}, },
}; };

View File

@ -78,9 +78,12 @@ export default {
// mouse events don't trigger at disabled button in Chrome // mouse events don't trigger at disabled button in Chrome
// https://github.com/react-component/tooltip/issues/18 // https://github.com/react-component/tooltip/issues/18
getDisabledCompatibleChildren(ele) { getDisabledCompatibleChildren(ele) {
const isAntBtn = ele.componentOptions && ele.componentOptions.Ctor.options.__ANT_BUTTON; const options = (ele.componentOptions && ele.componentOptions.Ctor.options) || {};
if ( if (
(isAntBtn && ((options.__ANT_BUTTON === true ||
options.__ANT_SWITCH === true ||
options.__ANT_CHECKBOX === true) &&
(ele.componentOptions.propsData.disabled || (ele.componentOptions.propsData.disabled ||
ele.componentOptions.propsData.disabled === '')) || ele.componentOptions.propsData.disabled === '')) ||
(ele.tag === 'button' && (ele.tag === 'button' &&
@ -125,8 +128,16 @@ export default {
}, },
isNoTitle() { isNoTitle() {
const { $slots, title } = this; const title = getComponentFromProp(this, 'title');
return !$slots.title && !title; return !title && title !== 0;
},
getOverlay() {
const title = getComponentFromProp(this, 'title');
if (title === 0) {
return title;
}
return title || '';
}, },
// //
@ -189,6 +200,7 @@ export default {
prefixCls, prefixCls,
getTooltipContainer: getPopupContainer || getContextPopupContainer, getTooltipContainer: getPopupContainer || getContextPopupContainer,
builtinPlacements: this.getPlacements(), builtinPlacements: this.getPlacements(),
overlay: this.getOverlay(),
visible: sVisible, visible: sVisible,
}, },
ref: 'tooltip', ref: 'tooltip',
@ -200,7 +212,6 @@ export default {
}; };
return ( return (
<VcTooltip {...tooltipProps}> <VcTooltip {...tooltipProps}>
<template slot="overlay">{getComponentFromProp(this, 'title')}</template>
{sVisible ? cloneElement(child, { class: childCls }) : child} {sVisible ? cloneElement(child, { class: childCls }) : child}
</VcTooltip> </VcTooltip>
); );

View File

@ -1,8 +1,10 @@
import { asyncExpect } from '@/tests/utils'; import { asyncExpect } from '@/tests/utils';
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import Tooltip from '..'; import Tooltip from '..';
import mountTest from '../../../tests/shared/mountTest';
describe('Tooltip', () => { describe('Tooltip', () => {
mountTest(Tooltip);
it('check `onVisibleChange` arguments', async () => { it('check `onVisibleChange` arguments', async () => {
const onVisibleChange = jest.fn(); const onVisibleChange = jest.fn();
const wrapper = mount( const wrapper = mount(

View File

@ -37,15 +37,12 @@ export default {
return ( return (
<div> <div>
<md cn={md.cn} us={md.us} /> <md cn={md.cn} us={md.us} />
<br /> <demo-sort cols="2">
<Basic /> <Basic />
<br /> <Placement />
<Placement /> <ArrowPointAtCenter />
<br /> <AutoAdjustOverflow />
<ArrowPointAtCenter /> </demo-sort>
<br />
<AutoAdjustOverflow />
<br />
<api> <api>
<template slot="cn"> <template slot="cn">
<CN /> <CN />

View File

@ -5,7 +5,7 @@
<us> <us>
#### Placement #### Placement
The ToolTip has 12 placements choice. There are 12 placement options available.
</us> </us>
```tpl ```tpl

View File

@ -11,7 +11,7 @@ export default {
props: { props: {
cols: { cols: {
type: [Number, String], type: [Number, String],
default: 1, default: 2,
}, },
}, },
inject: { inject: {