Skip to content

Commit

Permalink
fix(pagination): accessibility improvements (#408)
Browse files Browse the repository at this point in the history
Co-authored-by: Pratik Galoria <[email protected]>
  • Loading branch information
pratikgaloria and pratikgaloria authored Feb 9, 2023
1 parent e45a18f commit 336462b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/components/pagination/bl-pagination.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
align-items: center;
list-style: none;
user-select: none;
gap: var(--bl-size-3xs);
}

.dots {
Expand Down
10 changes: 5 additions & 5 deletions src/components/pagination/bl-pagination.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ describe('bl-pagination', () => {
assert.shadowDom.equal(
el,
`
<div class="pagination">
<nav class="pagination" aria-label="Pagination">
<div class="page-container">
<bl-button kind="neutral" variant="tertiary" icon="arrow_left" class="previous" disabled="" size="medium"></bl-button>
<bl-button kind="neutral" variant="tertiary" icon="arrow_left" label="Previous" class="previous" disabled="" size="medium"></bl-button>
<ul class="page-list">
<li>
<bl-button variant="primary" kind="neutral" size="medium">1</bl-button>
<bl-button variant="primary" kind="neutral" aria-current="page" label="Page 1" size="medium">1</bl-button>
</li>
</ul>
<bl-button kind="neutral" variant="tertiary" icon="arrow_right" class="next" size="medium" disabled=""></bl-button>
<bl-button kind="neutral" variant="tertiary" icon="arrow_right" label="Next" class="next" size="medium" disabled=""></bl-button>
</div>
</div>
</nav>
`
);
});
Expand Down
12 changes: 10 additions & 2 deletions src/components/pagination/bl-pagination.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CSSResultGroup, html, LitElement, TemplateResult, PropertyValues } from 'lit';
import { customElement, property, state } from 'lit/decorators.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import { event, EventDispatcher } from '../../utilities/event';
import '../button/bl-button';
import '../input/bl-input';
Expand Down Expand Up @@ -185,13 +186,16 @@ export default class BlPagination extends LitElement {

private _renderSinglePage(page: number | string) {
if (typeof page === 'string') {
return html`<span class="dots"></span>`;
return html`<li class="dots"></li>`;
}
const ariaCurrent = this.currentPage === page ? 'page' : undefined;
return html` <li>
<bl-button
@click="${() => this._changePage(page)}"
variant=${this.currentPage === page ? 'primary' : 'tertiary'}
kind="neutral"
label="Page ${page}"
aria-current=${ifDefined(ariaCurrent)}
>
${page}
</bl-button>
Expand All @@ -207,6 +211,7 @@ export default class BlPagination extends LitElement {
kind="neutral"
icon="arrow_left"
class="previous"
label="Previous"
?disabled=${this.currentPage === 1}
></bl-button>
<ul class="page-list">
Expand All @@ -220,6 +225,7 @@ export default class BlPagination extends LitElement {
kind="neutral"
icon="arrow_right"
class="next"
label="Next"
?disabled=${this.currentPage === this._getLastPage()}
></bl-button>
</div>
Expand Down Expand Up @@ -256,7 +262,9 @@ export default class BlPagination extends LitElement {
return html` <div class="pagination-helpers">${selectEl} ${jumperEl}</div> `;
};

return html` <div class="pagination">${getHelperElements()} ${this.renderPages()}</div>`;
return html` <nav class="pagination" aria-label="Pagination">
${getHelperElements()} ${this.renderPages()}
</nav>`;
}
}

Expand Down

0 comments on commit 336462b

Please sign in to comment.