Skip to content

Commit ba5b5a6

Browse files
docs(pagination): put current page on link element for a11y (#41154)
* docs(pagination): put current page on link element for a11y * Reorganize and rewrite * Update pagination.mdx --------- Co-authored-by: Mark Otto <markdotto@gmail.com>
1 parent 1184417 commit ba5b5a6

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

site/src/content/docs/components/pagination.mdx

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,38 +42,42 @@ Looking to use an icon or symbol in place of text for some pagination links? Be
4242
</ul>
4343
</nav>`} />
4444

45-
## Disabled and active states
45+
## Active
4646

47-
Pagination links are customizable for different circumstances. Use `.disabled` for links that appear un-clickable and `.active` to indicate the current page.
48-
49-
While the `.disabled` class uses `pointer-events: none` to _try_ to disable the link functionality of `<a>`s, that CSS property is not yet standardized and doesn’t account for keyboard navigation. As such, you should always add `tabindex="-1"` on disabled links and use custom JavaScript to fully disable their functionality.
47+
Add `.active` to indicate a `.page-item` is the one currently being viewed. If using an `<a>` on the current page, `aria-current="page"` should be added for assistive technologies.
5048

5149
<Example code={`<nav aria-label="...">
5250
<ul class="pagination">
53-
<li class="page-item disabled">
54-
<a class="page-link">Previous</a>
55-
</li>
51+
<li class="page-item"><a href="#" class="page-link">Previous</a></li>
5652
<li class="page-item"><a class="page-link" href="#">1</a></li>
57-
<li class="page-item active" aria-current="page">
58-
<a class="page-link" href="#">2</a>
53+
<li class="page-item active">
54+
<a class="page-link" href="#" aria-current="page">2</a>
5955
</li>
6056
<li class="page-item"><a class="page-link" href="#">3</a></li>
61-
<li class="page-item">
62-
<a class="page-link" href="#">Next</a>
63-
</li>
57+
<li class="page-item"><a class="page-link" href="#">Next</a></li>
6458
</ul>
6559
</nav>`} />
6660

67-
You can optionally swap out active or disabled anchors for `<span>`, or omit the anchor in the case of the prev/next arrows, to remove click functionality and prevent keyboard focus while retaining intended styles.
61+
If using a non-interactive element, like a `<span>` for the current page, you may omit the `aria-current` attribute.
62+
63+
```html
64+
<li class="page-item active">
65+
<span class="page-link">2</span>
66+
</li>
67+
```
68+
69+
## Disabled
70+
71+
Add `.disabled` to a `.page-item` to make it appear un-clickable. While `.disabled` uses `pointer-events: none` to disable the link‘s interactivity, that CSS property is not yet standardized and doesn’t account for keyboard navigation. As such, you should always add `tabindex="-1"` on disabled links and use custom JavaScript to fully disable their functionality.
6872

6973
<Example code={`<nav aria-label="...">
7074
<ul class="pagination">
7175
<li class="page-item disabled">
72-
<span class="page-link">Previous</span>
76+
<a class="page-link">Previous</a>
7377
</li>
7478
<li class="page-item"><a class="page-link" href="#">1</a></li>
75-
<li class="page-item active" aria-current="page">
76-
<span class="page-link">2</span>
79+
<li class="page-item active">
80+
<a class="page-link" href="#" aria-current="page">2</a>
7781
</li>
7882
<li class="page-item"><a class="page-link" href="#">3</a></li>
7983
<li class="page-item">
@@ -82,14 +86,22 @@ You can optionally swap out active or disabled anchors for `<span>`, or omit the
8286
</ul>
8387
</nav>`} />
8488

89+
And just like active page items, you can swap out the disabled `<a>` for a `<span>` to remove click functionality and prevent keyboard focus while retaining intended styles.
90+
91+
```html
92+
<li class="page-item disabled">
93+
<span class="page-link">Previous</span>
94+
</li>
95+
```
96+
8597
## Sizing
8698

8799
Fancy larger or smaller pagination? Add `.pagination-lg` or `.pagination-sm` for additional sizes.
88100

89101
<Example code={`<nav aria-label="...">
90102
<ul class="pagination pagination-lg">
91-
<li class="page-item active" aria-current="page">
92-
<span class="page-link">1</span>
103+
<li class="page-item active" >
104+
<a class="page-link" aria-current="page">1</a>
93105
</li>
94106
<li class="page-item"><a class="page-link" href="#">2</a></li>
95107
<li class="page-item"><a class="page-link" href="#">3</a></li>
@@ -98,8 +110,8 @@ Fancy larger or smaller pagination? Add `.pagination-lg` or `.pagination-sm` for
98110

99111
<Example code={`<nav aria-label="...">
100112
<ul class="pagination pagination-sm">
101-
<li class="page-item active" aria-current="page">
102-
<span class="page-link">1</span>
113+
<li class="page-item active">
114+
<a class="page-link" aria-current="page">1</a>
103115
</li>
104116
<li class="page-item"><a class="page-link" href="#">2</a></li>
105117
<li class="page-item"><a class="page-link" href="#">3</a></li>

0 commit comments

Comments
 (0)