Skip to content

Commit 5fa3b4f

Browse files
committed
fix: fix focus changing in CPagination component
1 parent eadf46e commit 5fa3b4f

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

src/components/pagination/CPagination.vue

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
:class="[{ 'active': activePage === item }, 'page-item']"
3838
>
3939
<CLink
40-
class="page-link"
41-
@click="setPage(item)"
42-
:aria-label="`Go to page ${item}`"
40+
class="page-link c-page-link-number"
41+
@click="setPage(item, $event)"
42+
:aria-label="activePage === item ? `Current page ${item}` : `Go to page ${item}`"
4343
>
4444
{{item}}
4545
</CLink>
@@ -199,17 +199,22 @@
199199
}
200200
},
201201
methods: {
202-
setPage (number) {
202+
setPage (number, e = false) {
203203
if (number !== this.activePage) {
204204
this.$emit('update:activePage', number)
205+
if (e) {
206+
const items = this.$el.getElementsByClassName('c-page-link-number')
207+
const focused = Number(e.target.innerHTML)
208+
this.$nextTick(() => {
209+
for (let i = 0; i < items.length; i++) {
210+
if (Number(items[i].innerHTML) === focused) {
211+
items[i].focus()
212+
}
213+
}
214+
})
215+
}
205216
}
206217
}
207218
}
208219
}
209220
</script>
210-
211-
<style>
212-
.page-link:focus {
213-
box-shadow: none;
214-
}
215-
</style>

src/components/pagination/tests/__snapshots__/CPagination.spec.js.snap

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ exports[`CPagination renders correctly 1`] = `
4747
class="active page-item"
4848
>
4949
<a
50-
aria-label="Go to page 1"
51-
class="page-link"
50+
aria-label="Current page 1"
51+
class="page-link c-page-link-number"
5252
href="#"
5353
target="_self"
5454
>
@@ -62,7 +62,7 @@ exports[`CPagination renders correctly 1`] = `
6262
>
6363
<a
6464
aria-label="Go to page 2"
65-
class="page-link"
65+
class="page-link c-page-link-number"
6666
href="#"
6767
target="_self"
6868
>
@@ -76,7 +76,7 @@ exports[`CPagination renders correctly 1`] = `
7676
>
7777
<a
7878
aria-label="Go to page 3"
79-
class="page-link"
79+
class="page-link c-page-link-number"
8080
href="#"
8181
target="_self"
8282
>
@@ -90,7 +90,7 @@ exports[`CPagination renders correctly 1`] = `
9090
>
9191
<a
9292
aria-label="Go to page 4"
93-
class="page-link"
93+
class="page-link c-page-link-number"
9494
href="#"
9595
target="_self"
9696
>
@@ -162,7 +162,7 @@ exports[`CPagination renders correctly 2`] = `
162162
>
163163
<a
164164
aria-label="Go to page 6"
165-
class="page-link"
165+
class="page-link c-page-link-number"
166166
href="#"
167167
target="_self"
168168
>
@@ -176,7 +176,7 @@ exports[`CPagination renders correctly 2`] = `
176176
>
177177
<a
178178
aria-label="Go to page 7"
179-
class="page-link"
179+
class="page-link c-page-link-number"
180180
href="#"
181181
target="_self"
182182
>
@@ -190,7 +190,7 @@ exports[`CPagination renders correctly 2`] = `
190190
>
191191
<a
192192
aria-label="Go to page 8"
193-
class="page-link"
193+
class="page-link c-page-link-number"
194194
href="#"
195195
target="_self"
196196
>
@@ -203,8 +203,8 @@ exports[`CPagination renders correctly 2`] = `
203203
class="active page-item"
204204
>
205205
<a
206-
aria-label="Go to page 9"
207-
class="page-link"
206+
aria-label="Current page 9"
207+
class="page-link c-page-link-number"
208208
href="#"
209209
target="_self"
210210
>
@@ -218,7 +218,7 @@ exports[`CPagination renders correctly 2`] = `
218218
>
219219
<a
220220
aria-label="Go to page 10"
221-
class="page-link"
221+
class="page-link c-page-link-number"
222222
href="#"
223223
target="_self"
224224
>
@@ -232,7 +232,7 @@ exports[`CPagination renders correctly 2`] = `
232232
>
233233
<a
234234
aria-label="Go to page 11"
235-
class="page-link"
235+
class="page-link c-page-link-number"
236236
href="#"
237237
target="_self"
238238
>
@@ -246,7 +246,7 @@ exports[`CPagination renders correctly 2`] = `
246246
>
247247
<a
248248
aria-label="Go to page 12"
249-
class="page-link"
249+
class="page-link c-page-link-number"
250250
href="#"
251251
target="_self"
252252
>

0 commit comments

Comments
 (0)