diff --git a/packages/components/pagination/__tests__/pagination.test.ts b/packages/components/pagination/__tests__/pagination.test.ts index 2445aded85..de08307a1c 100644 --- a/packages/components/pagination/__tests__/pagination.test.ts +++ b/packages/components/pagination/__tests__/pagination.test.ts @@ -411,5 +411,28 @@ describe('Pagination', () => { * expect(style.outline).toBeTruthy() */ }) + + test('test tabindex disabled', async () => { + const wrapper = mount({ + setup() { + return () => { + return h(Pagination, { + total: 100, + disabled: true, + }) + } + }, + }) + + expect( + wrapper.find('.el-pager li:first-child').attributes('tabindex') + ).toBe('-1') + + await wrapper.setProps({ disabled: false }) + + expect( + wrapper.find('.el-pager li:first-child').attributes('tabindex') + ).toBe('0') + }) }) }) diff --git a/packages/components/pagination/src/components/pager.vue b/packages/components/pagination/src/components/pager.vue index b9cb6d3f75..40e77cdcd8 100644 --- a/packages/components/pagination/src/components/pager.vue +++ b/packages/components/pagination/src/components/pager.vue @@ -8,7 +8,7 @@ ]" class="number" :aria-current="currentPage === 1" - tabindex="0" + :tabindex="tabindex" > 1 @@ -20,7 +20,7 @@ nsIcon.b(), nsPager.is('disabled', disabled), ]" - tabindex="0" + :tabindex="tabindex" @mouseenter="onMouseEnter(true)" @mouseleave="quickPrevHover = false" @focus="onFocus(true)" @@ -38,7 +38,7 @@ ]" class="number" :aria-current="currentPage === pager" - tabindex="0" + :tabindex="tabindex" > {{ pager }} @@ -50,7 +50,7 @@ nsIcon.b(), nsPager.is('disabled', disabled), ]" - tabindex="0" + :tabindex="tabindex" @mouseenter="onMouseEnter()" @mouseleave="quickNextHover = false" @focus="onFocus()" @@ -67,7 +67,7 @@ ]" class="number" :aria-current="currentPage === pageCount" - tabindex="0" + :tabindex="tabindex" > {{ pageCount }} @@ -128,6 +128,7 @@ const pagers = computed(() => { } return array }) +const tabindex = computed(() => (props.disabled ? -1 : 0)) watchEffect(() => { const halfPagerCount = (props.pagerCount - 1) / 2 showPrevMore.value = false