diff --git a/src/tab/index.js b/src/tab/index.js index 2b3852d83..15996025d 100644 --- a/src/tab/index.js +++ b/src/tab/index.js @@ -1,4 +1,4 @@ -import { createNamespace } from '../utils'; +import { isDef, createNamespace } from '../utils'; import { ChildrenMixin } from '../mixins/relation'; import { routeProps } from '../utils/router'; @@ -22,7 +22,7 @@ export default createComponent({ computed: { computedName() { - return this.name || this.index; + return isDef(this.name) ? this.name : this.index; }, isActive() { diff --git a/src/tab/test/index.spec.js b/src/tab/test/index.spec.js index 9bac4bede..978918526 100644 --- a/src/tab/test/index.spec.js +++ b/src/tab/test/index.spec.js @@ -173,7 +173,6 @@ test('click event', async () => { expect(onDisabled).toHaveBeenCalledWith(1, 'title2'); }); - test('name prop', async () => { const onClick = jest.fn(); const onChange = jest.fn(); @@ -208,3 +207,23 @@ test('name prop', async () => { expect(onDisabled).toHaveBeenCalledWith('c', 'title3'); expect(onChange).toHaveBeenCalledTimes(1); }); + +test('set name to zero', async () => { + const onClick = jest.fn(); + + const wrapper = mount({ + template: ` + + Text + Text + + `, + methods: { + onClick + } + }); + + const tabs = wrapper.findAll('.van-tab'); + tabs.at(1).trigger('click'); + expect(onClick).toHaveBeenCalledWith(0, 'title2'); +});