Skip to content

Commit c686088

Browse files
authored
fix(b-pagination, b-pagination-nav): add UP/DOWN keyboard navigation support for JAWS (fixes #4322) (#4325)
1 parent 5fa7e22 commit c686088

File tree

4 files changed

+28
-20
lines changed

4 files changed

+28
-20
lines changed

src/components/pagination-nav/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,9 @@ recommended unless the content of the button textually conveys it's purpose.
465465
pattern.
466466

467467
- Tabbing into the pagination component will autofocus the current active page button
468-
- <kbd>LEFT</kbd> and <kbd>RIGHT</kbd> arrow keys will focus the previous and next buttons in the
469-
page list, respectively, and <kbd>ENTER</kbd> or <kbd>SPACE</kbd> keys will select (click) the
470-
focused page button
468+
- <kbd>LEFT</kbd> (or <kbd>UP</kbd>) and <kbd>RIGHT</kbd> (or <kbd>DOWN</kbd>) arrow keys will focus
469+
the previous and next buttons, respectively, in the page list
470+
- <kbd>ENTER</kbd> or <kbd>SPACE</kbd> keys will select (click) the currently focused page button
471471
- Pressing <kbd>TAB</kbd> will move to the next control or link on the page, while pressing
472472
<kbd>SHIFT</kbd>+<kbd>TAB</kbd> will move to the previous control or link on the page.
473473

src/components/pagination/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,9 @@ recommended unless the content of the button textually conveys it's purpose.
347347
pattern.
348348

349349
- Tabbing into the pagination component will autofocus the current active page button
350-
- <kbd>LEFT</kbd> and <kbd>RIGHT</kbd> arrow keys will focus the previous and next buttons in the
351-
page list, respectively, and <kbd>ENTER</kbd> or <kbd>SPACE</kbd> keys will select (click) the
352-
focused page button
350+
- <kbd>LEFT</kbd> (or <kbd>UP</kbd>) and <kbd>RIGHT</kbd> (or <kbd>DOWN</kbd>) arrow keys will focus
351+
the previous and next buttons, respectively, in the page list
352+
- <kbd>ENTER</kbd> or <kbd>SPACE</kbd> keys will select (click) the currently focused page button
353353
- Pressing <kbd>TAB</kbd> will move to the next control or link on the page, while pressing
354354
<kbd>SHIFT</kbd>+<kbd>TAB</kbd> will move to the previous control or link on the page.
355355

src/components/pagination/pagination.spec.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,6 @@ describe('pagination', () => {
864864
expect(document.activeElement).toEqual(links.at(3).element)
865865

866866
// LEFT
867-
// links.at(3).trigger('keydown.left')
868867
wrapper.trigger('keydown.left')
869868
await waitNT(wrapper.vm)
870869
expect(document.activeElement).toEqual(links.at(2).element)
@@ -874,6 +873,16 @@ describe('pagination', () => {
874873
await waitNT(wrapper.vm)
875874
expect(document.activeElement).toEqual(links.at(3).element)
876875

876+
// UP (same as LEFT)
877+
wrapper.trigger('keydown.up')
878+
await waitNT(wrapper.vm)
879+
expect(document.activeElement).toEqual(links.at(2).element)
880+
881+
// DOWN (same as RIGHT)
882+
links.at(2).trigger('keydown.down')
883+
await waitNT(wrapper.vm)
884+
expect(document.activeElement).toEqual(links.at(3).element)
885+
877886
// SHIFT-RIGHT
878887
links.at(2).trigger('keydown.right', { shiftKey: true })
879888
await waitNT(wrapper.vm)

src/mixins/pagination.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,17 @@ export default {
287287
})
288288
},
289289
methods: {
290+
handleKeyNav(evt) {
291+
const keyCode = evt.keyCode
292+
const shift = evt.shiftKey
293+
if (keyCode === KeyCodes.LEFT || keyCode === KeyCodes.UP) {
294+
evt.preventDefault()
295+
shift ? this.focusFirst() : this.focusPrev()
296+
} else if (keyCode === KeyCodes.RIGHT || keyCode === KeyCodes.DOWN) {
297+
evt.preventDefault()
298+
shift ? this.focusLast() : this.focusNext()
299+
}
300+
},
290301
getButtons() {
291302
// Return only buttons that are visible
292303
return selectAll('a.page-link', this.$el).filter(btn => isVisible(btn))
@@ -545,19 +556,7 @@ export default {
545556
'aria-disabled': disabled ? 'true' : 'false',
546557
'aria-label': this.ariaLabel || null
547558
},
548-
on: {
549-
keydown: evt => {
550-
const keyCode = evt.keyCode
551-
const shift = evt.shiftKey
552-
if (keyCode === KeyCodes.LEFT) {
553-
evt.preventDefault()
554-
shift ? this.focusFirst() : this.focusPrev()
555-
} else if (keyCode === KeyCodes.RIGHT) {
556-
evt.preventDefault()
557-
shift ? this.focusLast() : this.focusNext()
558-
}
559-
}
560-
}
559+
on: { keydown: this.handleKeyNav }
561560
},
562561
buttons
563562
)

0 commit comments

Comments
 (0)