Compare commits

...

2 Commits

Author SHA1 Message Date
neverland
a7081b7e80
chore: update labels in issue template (#9857) 2021-11-13 19:41:37 +08:00
neverland
e5ead06d12
fix(Tabbar): before-change not work in route mode (#9856)
* fix(Tabbar): before-change not work in route mode

* fix: upd

* test: add test case
2021-11-13 19:35:44 +08:00
10 changed files with 53 additions and 24 deletions

View File

@ -1,7 +1,7 @@
name: 我要反馈 Vant 的 Bug
description: 通过标准模板进行 Bug 反馈。
title: "[Bug Report] 在此填写标题"
labels: ["🐞 bug"]
title: "[Bug Report] 在此填写标题"
labels: ["bug: need confirm"]
body:
- type: markdown
attributes:

View File

@ -1,7 +1,7 @@
name: 我要反馈 Vant Cli 的 Bug
description: 通过标准模板进行 Bug 反馈。
title: "[Bug Report] 在此填写标题"
labels: ["🐞 bug", "cli"]
title: "[Bug Report] 在此填写标题"
labels: ["bug: need confirm", "cli"]
body:
- type: markdown
attributes:

View File

@ -1,7 +1,7 @@
name: 我想要一个 Vant 的新功能
description: 通过标准模板描述一下你的功能需求。
title: "[Feature Request] 在此填写标题"
labels: ["💡 feature"]
title: "[Feature Request] 在此填写标题"
labels: ["feature: need confirm"]
body:
- type: markdown
attributes:

View File

@ -1,7 +1,7 @@
name: 我想要一个 Vant Cli 的新功能
description: 通过标准模板描述一下你的功能需求。
title: "[Feature Request] 在此填写标题"
labels: ["💡 feature", "cli"]
title: "[Feature Request] 在此填写标题"
labels: ["feature: need confirm", "cli"]
body:
- type: markdown
attributes:

View File

@ -1,7 +1,7 @@
name: Bug Report
description: Use issue template to report a bug.
title: "[Bug Report] Title"
labels: ["🐞 bug"]
labels: ["bug: need confirm"]
body:
- type: input
id: reproduce

View File

@ -1,7 +1,7 @@
name: Feature Request
description: Use issue template to request a new feature.
title: "[Feature Request] Title"
labels: ["💡 feature"]
labels: ["feature: need confirm"]
body:
- type: textarea
id: description

View File

@ -5,6 +5,7 @@
"dev": "pnpm dev --dir ./packages/vant",
"lint": "pnpm lint --dir ./packages/vant",
"test": "pnpm test --dir ./packages/vant",
"test:watch": "pnpm test:watch --dir ./packages/vant",
"build": "pnpm build --dir ./packages/vant",
"build:site": "pnpm build:site --dir ./packages/vant"
},

View File

@ -63,13 +63,14 @@ export default defineComponent({
return pathMatched || nameMatched;
}
return (props.name || index.value) === modelValue;
return (props.name ?? index.value) === modelValue;
});
const onClick = (event: MouseEvent) => {
parent.setActive(props.name ?? index.value);
if (!active.value) {
parent.setActive(props.name ?? index.value, route);
}
emit('click', event);
route();
};
const renderIcon = () => {

View File

@ -44,7 +44,7 @@ export type TabbarProps = ExtractPropTypes<typeof tabbarProps>;
export type TabbarProvide = {
props: TabbarProps;
setActive: (active: number | string) => void;
setActive: (active: number | string, afterChange: () => void) => void;
};
export const TABBAR_KEY: InjectionKey<TabbarProvide> = Symbol(name);
@ -83,16 +83,15 @@ export default defineComponent({
);
};
const setActive = (active: number | string) => {
if (active !== props.modelValue) {
callInterceptor(props.beforeChange, {
args: [active],
done() {
emit('update:modelValue', active);
emit('change', active);
},
});
}
const setActive = (active: number | string, afterChange: () => void) => {
callInterceptor(props.beforeChange, {
args: [active],
done() {
emit('update:modelValue', active);
emit('change', active);
afterChange();
},
});
};
linkChildren({ props, setActive });

View File

@ -69,6 +69,34 @@ test('should match active tab by route path in route mode', async () => {
expect(items[3].classes()).not.toContain(activeClass);
});
test('should allow to use before-change prop in route mode', async () => {
const wrapper = mount(
{
render: () => (
<Tabbar route beforeChange={() => false}>
<TabbarItem replace to="/">
Tab
</TabbarItem>
<TabbarItem replace to="/search">
Tab
</TabbarItem>
</Tabbar>
),
},
{
global: {
mocks: getMockRouter(),
},
}
);
const items = wrapper.findAll('.van-tabbar-item');
expect(items[0].classes()).toContain(activeClass);
await items[1].trigger('click');
expect(items[1].classes()).not.toContain(activeClass);
});
test('should match active tab by route name in route mode', async () => {
const wrapper = mount(
{