[new feature] Tabs: support switch tabs with swipe gestrue in the content (#694)
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
<template>
|
||||
<van-tabs :active="active" :duration="duration" @click="handleTabClick" @disabled="handleTabDisabledClick" :sticky="sticky">
|
||||
<van-tabs
|
||||
:active="active"
|
||||
:duration="duration"
|
||||
:sticky="sticky"
|
||||
:swipeable="swipeable"
|
||||
@click="handleTabClick"
|
||||
@disabled="handleTabDisabledClick"
|
||||
>
|
||||
<van-tab :title="firstTabTitle" :disabled="firstTabDisabled">内容一</van-tab>
|
||||
<van-tab title="选项二">内容二</van-tab>
|
||||
<van-tab title="选项三" disabled>内容三</van-tab>
|
||||
@@ -17,7 +24,8 @@ export default {
|
||||
firstTabDisabled: {
|
||||
type: Boolean
|
||||
},
|
||||
sticky: Boolean
|
||||
sticky: Boolean,
|
||||
swipeable: Boolean
|
||||
},
|
||||
|
||||
data() {
|
||||
|
||||
+32
-1
@@ -2,6 +2,7 @@ import Tabs from 'packages/tabs';
|
||||
import { mount } from 'avoriaz';
|
||||
import TabsTestComponent from '../components/tabs';
|
||||
import MoreTabsTestComponent from '../components/more-tabs';
|
||||
import { triggerTouch } from '../utils';
|
||||
|
||||
describe('Tabs', () => {
|
||||
let wrapper;
|
||||
@@ -114,7 +115,7 @@ describe('Tabs', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('sticky', (done) => {
|
||||
it('create a sticky tabs', (done) => {
|
||||
wrapper = mount(TabsTestComponent, {
|
||||
attachToDocument: true,
|
||||
propsData: {
|
||||
@@ -129,4 +130,34 @@ describe('Tabs', () => {
|
||||
done();
|
||||
}, 30);
|
||||
});
|
||||
|
||||
it('create a swipeable tabs', (done) => {
|
||||
wrapper = mount(TabsTestComponent, {
|
||||
attachToDocument: true,
|
||||
propsData: {
|
||||
swipeable: true
|
||||
}
|
||||
});
|
||||
|
||||
const tabsContainer = wrapper.find('.van-tabs')[0];
|
||||
const tabContent = wrapper.find('.van-tabs__content')[0];
|
||||
|
||||
expect(tabsContainer.vNode.child.curActive).to.equal(0);
|
||||
|
||||
wrapper.vm.$nextTick(() => {
|
||||
triggerTouch(tabContent, 'touchstart', 0, 0);
|
||||
triggerTouch(tabContent, 'touchmove', -100, 0);
|
||||
|
||||
setTimeout(() => {
|
||||
expect(tabsContainer.vNode.child.curActive).to.equal(1);
|
||||
|
||||
triggerTouch(tabContent, 'touchstart', 0, 0);
|
||||
triggerTouch(tabContent, 'touchmove', 100, 0);
|
||||
setTimeout(() => {
|
||||
expect(tabsContainer.vNode.child.curActive).to.equal(0);
|
||||
done();
|
||||
}, 500);
|
||||
}, 500);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user