Skip to content

Commit 7016a95

Browse files
fix(pagination): focus buttons web components (#18165)
* fix(pagination): focus buttons web components * fix(pagination): button svgs
1 parent 1004190 commit 7016a95

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

packages/web-components/src/components/button/button.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ $css--plex: true !default;
4949
:host(#{$prefix}-button[pagination]),
5050
:host(#{$prefix}-modal-footer-button[pagination]) {
5151
.#{$prefix}--btn {
52+
padding: 0;
5253
border: none;
5354
border-inline-start: 1px solid $border-subtle;
5455
transition: none;

packages/web-components/src/components/pagination/pagination.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ class CDSPagination extends FocusMixin(HostListenerMixin(LitElement)) {
124124
if (newStart !== oldStart) {
125125
this._handleUserInitiatedChangeStart(newStart);
126126
}
127+
// reset focus to forward button if it reaches the beginning
128+
if (this.page === 1) {
129+
const { selectorForwardButton } = this
130+
.constructor as typeof CDSPagination;
131+
(
132+
this.shadowRoot?.querySelector(
133+
`[button-class-name*=${selectorForwardButton}]`
134+
) as HTMLElement
135+
).focus();
136+
}
127137
}
128138

129139
/**
@@ -136,6 +146,16 @@ class CDSPagination extends FocusMixin(HostListenerMixin(LitElement)) {
136146
if (newStart < (totalItems == null ? Infinity : totalItems)) {
137147
this._handleUserInitiatedChangeStart(newStart);
138148
}
149+
// reset focus to previous button if it reaches the end
150+
if (this.page === this.totalPages) {
151+
const { selectorPreviousButton } = this
152+
.constructor as typeof CDSPagination;
153+
(
154+
this.shadowRoot?.querySelector(
155+
`[button-class-name*=${selectorPreviousButton}]`
156+
) as HTMLElement
157+
).focus();
158+
}
139159
}
140160

141161
/**
@@ -470,6 +490,20 @@ class CDSPagination extends FocusMixin(HostListenerMixin(LitElement)) {
470490
return `${prefix}-select`;
471491
}
472492

493+
/**
494+
* A selector that will return the previous button.
495+
*/
496+
static get selectorPreviousButton() {
497+
return `${prefix}--pagination__button--backward`;
498+
}
499+
500+
/**
501+
* A selector that will return the forward button.
502+
*/
503+
static get selectorForwardButton() {
504+
return `${prefix}--pagination__button--forward`;
505+
}
506+
473507
/**
474508
* The name of the custom event fired after the current row number is changed.
475509
*/

0 commit comments

Comments
 (0)