Skip to content

Commit

Permalink
fix(pagination): focus buttons web components (#18165)
Browse files Browse the repository at this point in the history
* fix(pagination): focus buttons web components

* fix(pagination): button svgs
  • Loading branch information
ariellalgilmore authored Dec 3, 2024
1 parent 1004190 commit 7016a95
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/web-components/src/components/button/button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ $css--plex: true !default;
:host(#{$prefix}-button[pagination]),
:host(#{$prefix}-modal-footer-button[pagination]) {
.#{$prefix}--btn {
padding: 0;
border: none;
border-inline-start: 1px solid $border-subtle;
transition: none;
Expand Down
34 changes: 34 additions & 0 deletions packages/web-components/src/components/pagination/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ class CDSPagination extends FocusMixin(HostListenerMixin(LitElement)) {
if (newStart !== oldStart) {
this._handleUserInitiatedChangeStart(newStart);
}
// reset focus to forward button if it reaches the beginning
if (this.page === 1) {
const { selectorForwardButton } = this
.constructor as typeof CDSPagination;
(
this.shadowRoot?.querySelector(
`[button-class-name*=${selectorForwardButton}]`
) as HTMLElement
).focus();
}
}

/**
Expand All @@ -136,6 +146,16 @@ class CDSPagination extends FocusMixin(HostListenerMixin(LitElement)) {
if (newStart < (totalItems == null ? Infinity : totalItems)) {
this._handleUserInitiatedChangeStart(newStart);
}
// reset focus to previous button if it reaches the end
if (this.page === this.totalPages) {
const { selectorPreviousButton } = this
.constructor as typeof CDSPagination;
(
this.shadowRoot?.querySelector(
`[button-class-name*=${selectorPreviousButton}]`
) as HTMLElement
).focus();
}
}

/**
Expand Down Expand Up @@ -470,6 +490,20 @@ class CDSPagination extends FocusMixin(HostListenerMixin(LitElement)) {
return `${prefix}-select`;
}

/**
* A selector that will return the previous button.
*/
static get selectorPreviousButton() {
return `${prefix}--pagination__button--backward`;
}

/**
* A selector that will return the forward button.
*/
static get selectorForwardButton() {
return `${prefix}--pagination__button--forward`;
}

/**
* The name of the custom event fired after the current row number is changed.
*/
Expand Down

0 comments on commit 7016a95

Please sign in to comment.