Skip to content

Accessibility improvements to the Comments Pagination block #70729

Description

@t-hamano

What problem does this address?

The core the_comments_pagination() function displays a link to the previous comment, pagination, and a link to the next comment, wrapped in a nav element nav element with an aria-label attribute:

<nav class="navigation comments-pagination" aria-label="Comments pagination">
  <h2 class="screen-reader-text">Comments pagination</h2>
  <div class="nav-links">
    <a class="prev page-numbers" href="http://localhost:8888/post-1/comment-page-1/#comments">« Previous</a>
    <a class="page-numbers" href="http://localhost:8888/post-1/comment-page-1/#comments">1</a>
    <span aria-current="page" class="page-numbers current">2</span>
    <a class="page-numbers" href="http://localhost:8888/post-1/comment-page-3/#comments">3</a>
    <a class="page-numbers" href="http://localhost:8888/post-1/comment-page-4/#comments">4</a>
    <a class="next page-numbers" href="http://localhost:8888/post-1/comment-page-3/#comments">Next »</a>
  </div>
</nav>

On the other hand, the Comments Pagination block displays child blocks wrapped in a div element with no aria-label attribute:

<div class="wp-block-comments-pagination is-layout-flex wp-block-comments-pagination-is-layout-flex">
  <a href="http://localhost:8888/post-1/comment-page-1/#comments" class="wp-block-comments-pagination-previous">Older Comments</a>
  <div class="wp-block-comments-pagination-numbers">
    <a class="page-numbers" href="http://localhost:8888/post-1/comment-page-1/#comments">1</a>
    <span aria-current="page" class="page-numbers current">2</span>
    <a class="page-numbers" href="http://localhost:8888/post-1/comment-page-3/#comments">3</a>
    <a class="page-numbers" href="http://localhost:8888/post-1/comment-page-4/#comments">4</a>
  </div>
  <a href="http://localhost:8888/post-1/comment-page-3/#comments" class="wp-block-comments-pagination-next">Newer Comments</a>
</div>

What is your proposed solution?

  • Change the wrapper element from div to nav.
  • Add aria-label="Comments pagination" to the wrapper element.

This approach is already implemented in the Query Pagination block:

$wrapper_attributes = get_block_wrapper_attributes(
array(
'aria-label' => __( 'Pagination' ),
'class' => $classes,
)
);
return sprintf(
'<nav %1$s>%2$s</nav>',
$wrapper_attributes,
$content
);

Metadata

Metadata

Assignees

Labels

Good First IssueAn issue that's suitable for someone looking to contribute for the first time[Block] Comments PaginationAffects the Comments Pagination Block[Focus] Accessibility (a11y)Changes that impact accessibility and need corresponding review (e.g. markup changes).[Status] In ProgressTracking issues with work in progress[Type] EnhancementA suggestion for improvement.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions