chore(Tabs): add deprecation warning (#9129)

* chore(Tabs): add deprecation warning

* chore: upd

* chore: upd
This commit is contained in:
neverland 2021-07-28 09:33:28 +08:00 committed by GitHub
parent a505a9a266
commit b7e6e68a92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 28 deletions

View File

@ -6,6 +6,9 @@ import { Tab } from '../tab';
import { Tabs } from '../tabs';
import { Icon } from '../icon';
// Types
import type { TabsClickTabEventParams } from '../tabs/Tabs';
const [name, bem, t] = createNamespace('cascader');
export type CascaderOption = {
@ -187,9 +190,8 @@ export default defineComponent({
const onClose = () => emit('close');
const onClickTab = (tabIndex: number, title: string) => {
emit('click-tab', tabIndex, title);
};
const onClickTab = ({ name, title }: TabsClickTabEventParams) =>
emit('click-tab', name, title);
const renderHeader = () => (
<div class={bem('header')}>
@ -279,7 +281,7 @@ export default defineComponent({
color={props.activeColor}
swipeThreshold={0}
swipeable={props.swipeable}
onClick={onClickTab}
onClickTab={onClickTab}
>
{state.tabs.map(renderTab)}
</Tabs>

View File

@ -3,6 +3,4 @@ import { inject, ComputedRef, InjectionKey } from 'vue';
// eslint-disable-next-line
export const TAB_STATUS_KEY: InjectionKey<ComputedRef<boolean>> = Symbol();
export function useTabStatus() {
return inject(TAB_STATUS_KEY, null);
}
export const useTabStatus = () => inject(TAB_STATUS_KEY, null);

View File

@ -2,27 +2,6 @@ import { mount, later } from '../../../test';
import { Tab } from '..';
import { Tabs } from '../../tabs';
test('should emit click event when tab is clicked', async () => {
const onClick = jest.fn();
const wrapper = mount({
render() {
return (
<Tabs onClick={onClick}>
<Tab title="title1">1</Tab>
<Tab title="title2">2</Tab>
</Tabs>
);
},
});
await later();
const tabs = wrapper.findAll('.van-tab');
await tabs[0].trigger('click');
expect(onClick).toHaveBeenCalledWith(0, 'title1');
});
test('should emit click-tab event when tab is clicked', async () => {
const onClickTab = jest.fn();

View File

@ -11,6 +11,7 @@ import {
CSSProperties,
defineComponent,
ExtractPropTypes,
getCurrentInstance,
ComponentPublicInstance,
} from 'vue';
@ -54,6 +55,13 @@ const [name, bem] = createNamespace('tabs');
export type TabsType = 'line' | 'card';
export type TabsClickTabEventParams = {
name: string | number;
title: string;
event: MouseEvent;
disabled: boolean;
};
const props = {
color: String,
border: Boolean,
@ -117,6 +125,20 @@ export default defineComponent({
],
setup(props, { emit, slots }) {
if (process.env.NODE_ENV !== 'production') {
const props = getCurrentInstance()?.vnode?.props;
if (props && 'onClick' in props) {
console.warn(
'[Vant] Tabs: "click" event is deprecated, using "click-tab" instead.'
);
}
if (props && 'onDisabled' in props) {
console.warn(
'[Vant] Tabs: "disabled" event is deprecated, using "click-tab" instead.'
);
}
}
let tabHeight: number;
let lockScroll: boolean;
let stickyFixed: boolean;

View File

@ -32,6 +32,7 @@ declare module 'vue' {
onPreview?: EventHandler;
onKeypress?: EventHandler;
onTouchend?: EventHandler;
onClickTab?: EventHandler;
onClickStep?: EventHandler;
onTouchmove?: EventHandler;
onTouchstart?: EventHandler;