feat(Tab): add scrollTo method (#6800)
This commit is contained in:
@@ -229,7 +229,7 @@ exports[`render nav-left & nav-right slot 1`] = `
|
||||
|
||||
exports[`rendered event 1`] = `<div role="tabpanel" class="van-tab__pane" style="">Text</div>`;
|
||||
|
||||
exports[`scrollspy 1`] = `
|
||||
exports[`scrollspy prop 1`] = `
|
||||
<div class="van-tabs van-tabs--line">
|
||||
<div>
|
||||
<div class="van-sticky">
|
||||
@@ -251,7 +251,7 @@ exports[`scrollspy 1`] = `
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`scrollspy 2`] = `
|
||||
exports[`scrollspy prop 2`] = `
|
||||
<div class="van-tabs van-tabs--line">
|
||||
<div>
|
||||
<div class="van-sticky">
|
||||
|
||||
@@ -258,7 +258,7 @@ test('info prop', () => {
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('scrollspy', async () => {
|
||||
test('scrollspy prop', async () => {
|
||||
const onChange = jest.fn();
|
||||
window.scrollTo = jest.fn();
|
||||
|
||||
@@ -288,6 +288,30 @@ test('scrollspy', async () => {
|
||||
expect(onChange).toHaveBeenCalledWith('c', 'title3');
|
||||
});
|
||||
|
||||
test('scrollTo method', async () => {
|
||||
const onChange = jest.fn();
|
||||
window.scrollTo = jest.fn();
|
||||
|
||||
mount({
|
||||
template: `
|
||||
<van-tabs scrollspy sticky @change="onChange" ref="root">
|
||||
<van-tab name="a" title="title1">Text</van-tab>
|
||||
<van-tab name="b" title="title2">Text</van-tab>
|
||||
<van-tab name="c" title="title3">Text</van-tab>
|
||||
</van-tabs>
|
||||
`,
|
||||
methods: {
|
||||
onChange,
|
||||
},
|
||||
mounted() {
|
||||
this.$refs.root.scrollTo('b');
|
||||
},
|
||||
});
|
||||
|
||||
await later();
|
||||
expect(onChange).toHaveBeenCalledWith('b', 'title2');
|
||||
});
|
||||
|
||||
test('rendered event', async () => {
|
||||
const onRendered = jest.fn();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user