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

View File

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

View File

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

View File

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

View File

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