From 4b0b051c53a397aa5e9baab73de4d7837053f715 Mon Sep 17 00:00:00 2001 From: qiang Date: Sat, 16 Jul 2022 19:01:03 +0800 Subject: [PATCH] fix(components): [tabs] disabled pane can still be focused (#8600) * fix(components): [tabs] disabled pane can still be focused * test(components): [tabs] modify the test * fix(components): [tabs] hide close button when Tab is disabled * chore(components): [tabs] optimize code * fix(theme-chalk): [tabs] the disabled style error --- packages/components/tabs/__tests__/tabs.test.ts | 11 +++-------- packages/components/tabs/src/tab-nav.tsx | 9 +++++---- packages/theme-chalk/src/tabs.scss | 2 +- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/packages/components/tabs/__tests__/tabs.test.ts b/packages/components/tabs/__tests__/tabs.test.ts index 38fc0072da..511da02a0c 100644 --- a/packages/components/tabs/__tests__/tabs.test.ts +++ b/packages/components/tabs/__tests__/tabs.test.ts @@ -634,7 +634,7 @@ describe('Tabs.vue', () => { }, template: ` - A + A B C D @@ -663,17 +663,12 @@ describe('Tabs.vue', () => { await wrapper .find('#tab-fourth') .trigger('keydown', { code: EVENT_CODE.right }) - expect(vm.activeName).toEqual('first') + expect(vm.activeName).toEqual('second') await wrapper - .find('#tab-first') + .find('#tab-second') .trigger('keydown', { code: EVENT_CODE.left }) expect(vm.activeName).toEqual('fourth') - - await wrapper - .find('#tab-fourth') - .trigger('keydown', { code: EVENT_CODE.left }) - expect(vm.activeName).toEqual('third') }) test('resize', async () => { diff --git a/packages/components/tabs/src/tab-nav.tsx b/packages/components/tabs/src/tab-nav.tsx index 400f8d32d1..a0ca400158 100644 --- a/packages/components/tabs/src/tab-nav.tsx +++ b/packages/components/tabs/src/tab-nav.tsx @@ -215,7 +215,7 @@ const TabNav = defineComponent({ // 左右上下键更换tab const tabList = Array.from( (e.currentTarget as HTMLDivElement).querySelectorAll( - '[role=tab]' + '[role=tab]:not(.is-disabled)' ) ) const currentIndex = tabList.indexOf(e.target as HTMLDivElement) @@ -308,8 +308,9 @@ const TabNav = defineComponent({ : null const tabs = props.panes.map((pane, index) => { + const disabled = pane.props.disabled const tabName = pane.props.name ?? pane.index ?? `${index}` - const closable: boolean = pane.isClosable || props.editable + const closable = !disabled && (pane.isClosable || props.editable) pane.index = `${index}` const btnClose = closable ? ( @@ -325,7 +326,7 @@ const TabNav = defineComponent({ ) : null const tabLabelContent = pane.slots.label?.() || pane.props.label - const tabindex = pane.active ? 0 : -1 + const tabindex = !disabled && pane.active ? 0 : -1 return (