mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
chore(Tabs): add deprecation warning (#9129)
* chore(Tabs): add deprecation warning * chore: upd * chore: upd
This commit is contained in:
parent
a505a9a266
commit
b7e6e68a92
@ -6,6 +6,9 @@ import { Tab } from '../tab';
|
|||||||
import { Tabs } from '../tabs';
|
import { Tabs } from '../tabs';
|
||||||
import { Icon } from '../icon';
|
import { Icon } from '../icon';
|
||||||
|
|
||||||
|
// Types
|
||||||
|
import type { TabsClickTabEventParams } from '../tabs/Tabs';
|
||||||
|
|
||||||
const [name, bem, t] = createNamespace('cascader');
|
const [name, bem, t] = createNamespace('cascader');
|
||||||
|
|
||||||
export type CascaderOption = {
|
export type CascaderOption = {
|
||||||
@ -187,9 +190,8 @@ export default defineComponent({
|
|||||||
|
|
||||||
const onClose = () => emit('close');
|
const onClose = () => emit('close');
|
||||||
|
|
||||||
const onClickTab = (tabIndex: number, title: string) => {
|
const onClickTab = ({ name, title }: TabsClickTabEventParams) =>
|
||||||
emit('click-tab', tabIndex, title);
|
emit('click-tab', name, title);
|
||||||
};
|
|
||||||
|
|
||||||
const renderHeader = () => (
|
const renderHeader = () => (
|
||||||
<div class={bem('header')}>
|
<div class={bem('header')}>
|
||||||
@ -279,7 +281,7 @@ export default defineComponent({
|
|||||||
color={props.activeColor}
|
color={props.activeColor}
|
||||||
swipeThreshold={0}
|
swipeThreshold={0}
|
||||||
swipeable={props.swipeable}
|
swipeable={props.swipeable}
|
||||||
onClick={onClickTab}
|
onClickTab={onClickTab}
|
||||||
>
|
>
|
||||||
{state.tabs.map(renderTab)}
|
{state.tabs.map(renderTab)}
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
@ -3,6 +3,4 @@ import { inject, ComputedRef, InjectionKey } from 'vue';
|
|||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
export const TAB_STATUS_KEY: InjectionKey<ComputedRef<boolean>> = Symbol();
|
export const TAB_STATUS_KEY: InjectionKey<ComputedRef<boolean>> = Symbol();
|
||||||
|
|
||||||
export function useTabStatus() {
|
export const useTabStatus = () => inject(TAB_STATUS_KEY, null);
|
||||||
return inject(TAB_STATUS_KEY, null);
|
|
||||||
}
|
|
||||||
|
@ -2,27 +2,6 @@ import { mount, later } from '../../../test';
|
|||||||
import { Tab } from '..';
|
import { Tab } from '..';
|
||||||
import { Tabs } from '../../tabs';
|
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 () => {
|
test('should emit click-tab event when tab is clicked', async () => {
|
||||||
const onClickTab = jest.fn();
|
const onClickTab = jest.fn();
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import {
|
|||||||
CSSProperties,
|
CSSProperties,
|
||||||
defineComponent,
|
defineComponent,
|
||||||
ExtractPropTypes,
|
ExtractPropTypes,
|
||||||
|
getCurrentInstance,
|
||||||
ComponentPublicInstance,
|
ComponentPublicInstance,
|
||||||
} from 'vue';
|
} from 'vue';
|
||||||
|
|
||||||
@ -54,6 +55,13 @@ const [name, bem] = createNamespace('tabs');
|
|||||||
|
|
||||||
export type TabsType = 'line' | 'card';
|
export type TabsType = 'line' | 'card';
|
||||||
|
|
||||||
|
export type TabsClickTabEventParams = {
|
||||||
|
name: string | number;
|
||||||
|
title: string;
|
||||||
|
event: MouseEvent;
|
||||||
|
disabled: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
const props = {
|
const props = {
|
||||||
color: String,
|
color: String,
|
||||||
border: Boolean,
|
border: Boolean,
|
||||||
@ -117,6 +125,20 @@ export default defineComponent({
|
|||||||
],
|
],
|
||||||
|
|
||||||
setup(props, { emit, slots }) {
|
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 tabHeight: number;
|
||||||
let lockScroll: boolean;
|
let lockScroll: boolean;
|
||||||
let stickyFixed: boolean;
|
let stickyFixed: boolean;
|
||||||
|
1
src/vue-tsx-shim.d.ts
vendored
1
src/vue-tsx-shim.d.ts
vendored
@ -32,6 +32,7 @@ declare module 'vue' {
|
|||||||
onPreview?: EventHandler;
|
onPreview?: EventHandler;
|
||||||
onKeypress?: EventHandler;
|
onKeypress?: EventHandler;
|
||||||
onTouchend?: EventHandler;
|
onTouchend?: EventHandler;
|
||||||
|
onClickTab?: EventHandler;
|
||||||
onClickStep?: EventHandler;
|
onClickStep?: EventHandler;
|
||||||
onTouchmove?: EventHandler;
|
onTouchmove?: EventHandler;
|
||||||
onTouchstart?: EventHandler;
|
onTouchstart?: EventHandler;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user