mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-08-07 21:19:45 +08:00
[bugfix] Tab: click event param missing (#3866)
This commit is contained in:
parent
aba5f59fdd
commit
a594774ee2
@ -146,6 +146,34 @@ test('border props', async () => {
|
|||||||
expect(wrapper).toMatchSnapshot();
|
expect(wrapper).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test('click event', async () => {
|
||||||
|
const onClick = jest.fn();
|
||||||
|
const onDisabled = jest.fn();
|
||||||
|
|
||||||
|
const wrapper = mount({
|
||||||
|
template: `
|
||||||
|
<van-tabs @click="onClick" @disabled="onDisabled">
|
||||||
|
<van-tab title="title1">Text</van-tab>
|
||||||
|
<van-tab title="title2" disabled>Text</van-tab>
|
||||||
|
</van-tabs>
|
||||||
|
`,
|
||||||
|
methods: {
|
||||||
|
onClick,
|
||||||
|
onDisabled
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const tabs = wrapper.findAll('.van-tab');
|
||||||
|
|
||||||
|
tabs.at(0).trigger('click');
|
||||||
|
expect(onClick).toHaveBeenCalledWith(0, 'title1');
|
||||||
|
|
||||||
|
tabs.at(1).trigger('click');
|
||||||
|
expect(onDisabled).toHaveBeenCalledWith(1, 'title2');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
test('name prop', async () => {
|
test('name prop', async () => {
|
||||||
const onClick = jest.fn();
|
const onClick = jest.fn();
|
||||||
const onChange = jest.fn();
|
const onChange = jest.fn();
|
||||||
|
@ -276,12 +276,12 @@ export default createComponent({
|
|||||||
|
|
||||||
// emit event when clicked
|
// emit event when clicked
|
||||||
onClick(index) {
|
onClick(index) {
|
||||||
const { title, disabled, name } = this.children[index];
|
const { title, disabled, computedName } = this.children[index];
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
this.$emit('disabled', name, title);
|
this.$emit('disabled', computedName, title);
|
||||||
} else {
|
} else {
|
||||||
this.setCurrentIndex(index);
|
this.setCurrentIndex(index);
|
||||||
this.$emit('click', name, title);
|
this.$emit('click', computedName, title);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user