Skip to content

Commit 9562853

Browse files
feat: improve pagination
- remove disabled buttons from pagination - add aria labels to pagination - add basic styles to pagination
1 parent ae4fb6d commit 9562853

File tree

3 files changed

+36
-30
lines changed

3 files changed

+36
-30
lines changed

src/php/views/partials/pagination.twig

+14-30
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,45 @@
11
{% if posts.pagination.pages is not empty %}
2-
<nav aria-label="Pagination">
3-
<ul>
2+
<nav aria-label="Pagination" class="cmp-pagination">
3+
<ul class="cmp-pagination__list">
44

55
{# First #}
66
{% if posts.pagination.pages|first and posts.pagination.pages|first.current != true %}
7-
<li>
8-
<a href="{{ posts.pagination.pages|first.link }}">First</a>
9-
</li>
10-
{% else %}
11-
<li>
12-
<button disabled>First</button>
7+
<li class="cmp-pagination__item">
8+
<a href="{{ posts.pagination.pages|first.link }}" aria-label="First Page">First</a>
139
</li>
1410
{% endif %}
1511

1612
{# Previous #}
1713
{% if posts.pagination.prev %}
18-
<li>
19-
<a href="{{ posts.pagination.prev.link }}">Previous</a>
20-
</li>
21-
{% else %}
22-
<li>
23-
<button disabled>Previous</button>
14+
<li class="cmp-pagination__item">
15+
<a href="{{ posts.pagination.prev.link }}" aria-label="Previous Page">Previous</a>
2416
</li>
2517
{% endif %}
2618

2719
{# Pages #}
2820
{% for page in posts.pagination.pages %}
2921
{% if page.link %}
30-
<li>
31-
<a href="{{ page.link }}" class="{{ page.class }}">{{ page.title }}</a>
22+
<li class="cmp-pagination__item">
23+
<a href="{{ page.link }}" class="{{ page.class }}" aria-label="Page {{ page.title }}">{{ page.title }}</a>
3224
</li>
3325
{% else %}
34-
<li>
35-
<span class="{{ page.class }}">{{ page.title }}</span>
26+
<li class="cmp-pagination__item">
27+
<span class="{{ page.class }}" {% if page.current %} aria-current="page"{% endif %}>{{ page.title }}</span>
3628
</li>
3729
{% endif %}
3830
{% endfor %}
3931

4032
{# Next #}
4133
{% if posts.pagination.next %}
42-
<li>
43-
<a href="{{ posts.pagination.next.link }}">Next</a>
44-
</li>
45-
{% else %}
46-
<li>
47-
<button disabled>Next</button>
34+
<li class="cmp-pagination__item">
35+
<a href="{{ posts.pagination.next.link }}" aria-label="Next Page">Next</a>
4836
</li>
4937
{% endif %}
5038

5139
{# Last #}
5240
{% if posts.pagination.pages|last and posts.pagination.pages|last.current != true %}
53-
<li>
54-
<a href="{{ posts.pagination.pages|last.link }}">Last</a>
55-
</li>
56-
{% else %}
57-
<li>
58-
<button disabled>Last</button>
41+
<li class="cmp-pagination__item">
42+
<a href="{{ posts.pagination.pages|last.link }}" aria-label="Last Page">Last</a>
5943
</li>
6044
{% endif %}
6145

src/scss/base.scss

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
// Specific UI components. This is where majority of our work takes place
6464
// and our UI components are often composed of Objects and Components
6565
@import 'components/main-nav';
66+
@import 'components/pagination';
6667
@import 'components/primary-sidebar';
6768
@import 'components/post-body';
6869
@import 'components/skip-to-content';

src/scss/components/_pagination.scss

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.cmp-pagination {
2+
margin-top: 1.5rem;
3+
4+
&__list {
5+
display: flex;
6+
flex-wrap: wrap;
7+
justify-content: center;
8+
list-style: none;
9+
margin: 0;
10+
padding: 0;
11+
}
12+
13+
&__item {
14+
display: inline-block;
15+
margin: 1rem;
16+
17+
& .current {
18+
cursor: default;
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)