Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyboard Accessibility Pagination Component #963

Merged
merged 18 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions mathesar_ui/src/component-library/icon/Icon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@
aria-label={label}
role={label ? 'img' : 'presentation'}
{...$$restProps}
on:click
on:mouseover
on:focus
on:mouseout
on:blur
>
{#if Array.isArray(path)}
{#each path as entry (entry)}
Expand Down
21 changes: 19 additions & 2 deletions mathesar_ui/src/component-library/pagination/Pagination.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,26 @@ ul.pagination {
margin: 0 2px;

a,
span {
button {
padding: 5px 3px;
min-width: 26px;
display: inline-block;
text-align: center;
cursor: pointer;

&:hover {
background-color: #aeb9be21;
}

&:disabled {
color: #ccc;
background-color: inherit;
cursor: not-allowed;
}
}

button:focus {
outline: #39a0f5 solid 1px;
}

.page {
Expand All @@ -25,7 +39,10 @@ ul.pagination {
background: #fff;
}

span {
button {
border: none;
background: inherit;

.ellipsis {
color: #afafaf;
}
Expand Down
42 changes: 24 additions & 18 deletions mathesar_ui/src/component-library/pagination/Pagination.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
// Total number of pages.
export let pageCount = 0;

// ARIA Label for component
export let ariaLabel = 'Pagination';

$: pageCount = Math.ceil(total / pageSize);
$: pageInfo = calculatePages(currentPage, pageCount);

Expand All @@ -45,23 +48,24 @@
}
</script>

<nav role="navigation" aria-label="Pagination Navigation">
<nav role="navigation" aria-label={ariaLabel}>
<ul class="pagination">
{#if pageCount > 1}
<li>
<span
<button
tabindex="0"
role="link"
aria-label="Previous"
on:click={(e) => setPage(e, currentPage - 1)}
disabled={currentPage === 1}
>
<Icon data={faAngleLeft} />
</span>
<Icon data={faAngleLeft} tabindex="-1" />
</button>
</li>
{/if}

{#if pageInfo.start > 1}
<li class:active={currentPage === pageInfo.start}>
pavish marked this conversation as resolved.
Show resolved Hide resolved
<li>
{#if getLink}
<a
tabindex="0"
Expand All @@ -74,28 +78,28 @@
1
</a>
{:else}
<span
<button
tabindex="0"
role="link"
aria-label="Goto Page 1"
class="page"
on:click={(e) => setPage(e, 1)}
>
1
</span>
</button>
{/if}
</li>
{#if pageInfo.start > 2}
<li>
<span
<button
tabindex="0"
role="link"
aria-label="Goto Page {pageInfo.prevPageWindow}"
on:click={(e) => setPage(e, pageInfo.prevPageWindow)}
>
<Icon class="ellipsis" data={faEllipsisH} />
<Icon class="arrow" data={faAngleDoubleLeft} />
</span>
</button>
</li>
{/if}
{/if}
Expand All @@ -117,7 +121,7 @@
{_page}
</a>
{:else}
<span
<button
tabindex="0"
role="link"
aria-label={currentPage === _page
Expand All @@ -128,26 +132,26 @@
aria-selected={currentPage === _page}
>
{_page}
</span>
</button>
{/if}
</li>
{/each}

{#if pageInfo.end < pageCount}
{#if pageInfo.end < pageCount - 1}
<li>
<span
<button
tabindex="0"
role="link"
aria-label="Goto Page {pageInfo.nextPageWindow}"
on:click={(e) => setPage(e, pageInfo.nextPageWindow)}
>
<Icon class="ellipsis" data={faEllipsisH} />
<Icon class="arrow" data={faAngleDoubleRight} />
</span>
</button>
</li>
{/if}
<li class:active={currentPage === pageInfo.end}>
<li>
{#if getLink}
<a
tabindex="0"
Expand All @@ -160,28 +164,30 @@
{pageCount}
</a>
{:else}
<span
<button
tabindex="0"
class="page"
role="link"
aria-label="Goto Page {pageCount}"
on:click={(e) => setPage(e, pageCount)}
>
{pageCount}
</span>
</button>
{/if}
</li>
{/if}

{#if pageCount > 1}
<li>
<span
<button
tabindex="0"
role="link"
aria-label="Next"
on:click={(e) => setPage(e, currentPage + 1)}
disabled={currentPage === pageCount}
>
<Icon data={faAngleRight} />
</span>
</button>
</li>
{/if}
</ul>
Expand Down