Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tabs): 修复组件item设置disabled时,还能滑动到过去的问题(#2486) #2559

Merged
merged 2 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/packages/__VUE/tabs/__tests__/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,37 @@ test('base Tabpane Props', async () => {
expect(tab3[0].html()).toContain('Tab 1');
});

test('base Tabpane disabled swipeable', async () => {
const wrapper = mount({
components: {
'nut-tabs': Tabs,
'nut-tab-pane': TabPane
},
template: `
<nut-tabs v-model="state.tab2value" swipeable>
<nut-tab-pane title="Tab 1" pane-key="0"> </nut-tab-pane>
<nut-tab-pane title="Tab 2" pane-key="1" :disabled="true"> Tab 2 </nut-tab-pane>
<nut-tab-pane title="Tab 3" pane-key="2"> Tab 3 </nut-tab-pane>
</nut-tabs>
`,
setup() {
const state = reactive({
tab2value: '0'
});
return { state };
}
});
await nextTick();
const tab = wrapper.findAll('.nut-tabs__titles-item');
expect(tab.length).toBe(3);
const tab1 = wrapper.findAll('.nut-tabs__titles-item')[1];
expect(tab1.classes()).toContain('disabled');
const tab2 = wrapper.findAll('.nut-tabs__titles-item')[0];
expect(tab2.classes()).toContain('active');
const tab3 = wrapper.findAll('.nut-tabs__titles-item__text');
expect(tab3[0].html()).toContain('Tab 1');
});

test('base click', async () => {
const wrapper = mount({
components: {
Expand Down
18 changes: 18 additions & 0 deletions src/packages/__VUE/tabs/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,28 @@
},
next: () => {
currentIndex.value += 1;
const nextDisabled = titles.value[currentIndex.value].disabled;
if (tabMethods.isEnd() && nextDisabled) {
tabMethods.prev();
return;
}
if (nextDisabled && currentIndex.value < titles.value.length - 1) {
tabMethods.next();
return;
}

Check warning on line 304 in src/packages/__VUE/tabs/index.vue

View check run for this annotation

Codecov / codecov/patch

src/packages/__VUE/tabs/index.vue#L296-L304

Added lines #L296 - L304 were not covered by tests
tabMethods.updateValue(titles.value[currentIndex.value]);
},
prev: () => {
currentIndex.value -= 1;
const prevDisabled = titles.value[currentIndex.value].disabled;
if (tabMethods.isBegin() && prevDisabled) {
tabMethods.next();
return;
}
if (prevDisabled && currentIndex.value > 0) {
tabMethods.prev();
return;
}

Check warning on line 317 in src/packages/__VUE/tabs/index.vue

View check run for this annotation

Codecov / codecov/patch

src/packages/__VUE/tabs/index.vue#L309-L317

Added lines #L309 - L317 were not covered by tests
tabMethods.updateValue(titles.value[currentIndex.value]);
},
updateValue: (item: Title) => {
Expand Down