Use pagination:
search results
and article archives) that consist of more than 100 items. If your list consists of fewer items you may not need to add pagination.Do not use pagination:
vf-button
to let the user move to the next page and a Back link to let them move to the previous page.Also see the recommendations by Nielsen Norman and the pagination compoment in gov.uk.
This component targets WCAG 2.1 AA accessibility.
Depending on your environment you'll want to use render
or include
. As a rule of thumb: server-side use include
, precompiled browser use render
. If you're using vf-eleventy you should use include
.
include
You'll need to pass a context object from your code or Yaml file (example), as well as the path to the Nunjucks template. Nunjucks' include
is an abstraction of render
and provides some additional portability.
{% set context fromYourYamlFile %}
- or -
{% set context = {
"exampleMultiColumns" : "false",
"component-type" : "block",
"previous_text" : "Previous",
"previous_url" : "JavaScript:Void(0);",
"next_text" : "Next",
"next_url" : "JavaScript:Void(0);",
"jumpBack_text" : -10,
"jumpBack_url" : "JavaScript:Void(0);",
"jumpForward_text" : 10,
"jumpForward_url" : "JavaScript:Void(0);",
"pagination__list" : [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],
}
%}
{% include "../path_to/vf-pagination/vf-pagination.njk" %}
render
This approach is best for bare-bones Nunjucks environments, such as precompiled templates with the Nunjucks slim runtime where include
is not be available.
{% render '@vf-pagination', {
"exampleMultiColumns" : "false",
"component-type" : "block",
"previous_text" : "Previous",
"previous_url" : "JavaScript:Void(0);",
"next_text" : "Next",
"next_url" : "JavaScript:Void(0);",
"jumpBack_text" : -10,
"jumpBack_url" : "JavaScript:Void(0);",
"jumpForward_text" : 10,
"jumpForward_url" : "JavaScript:Void(0);",
"pagination__list" : [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],}
%}
<nav class="vf-pagination" aria-label="Pagination">
<ul class="vf-pagination__list">
<li class="vf-pagination__item vf-pagination__item--previous-page">
<a href="JavaScript:Void(0);" class="vf-pagination__link">
Previous<span class="vf-u-sr-only"> page</span>
</a>
</li>
<li class="vf-pagination__item">
<a href="JavaScript:Void(0);" class="vf-pagination__link">
1<span class="vf-u-sr-only"> page</span>
</a>
</li>
<li class="vf-pagination__item">
<a href="JavaScript:Void(0);" class="vf-pagination__link">
2<span class="vf-u-sr-only"> page</span>
</a>
</li>
<li class="vf-pagination__item">
<span class="vf-pagination__label">...</span>
</li>
<li class="vf-pagination__item">
<a href="JavaScript:Void(0);" class="vf-pagination__link">
17<span class="vf-u-sr-only"> page</span>
</a>
</li>
<li class="vf-pagination__item vf-pagination__item--is-active">
<span class="vf-pagination__label" aria-current="page">
<span class="vf-u-sr-only">Page </span>18
</span>
</li>
<li class="vf-pagination__item">
<a href="JavaScript:Void(0);" class="vf-pagination__link">
19<span class="vf-u-sr-only"> page</span>
</a>
</li>
<li class="vf-pagination__item">
<span class="vf-pagination__label">...</span>
</li>
<li class="vf-pagination__item">
<a href="JavaScript:Void(0);" class="vf-pagination__link">
91<span class="vf-u-sr-only"> page</span>
</a>
</li>
<li class="vf-pagination__item">
<a href="JavaScript:Void(0);" class="vf-pagination__link">
92<span class="vf-u-sr-only"> page</span>
</a>
</li>
<li class="vf-pagination__item vf-pagination__item--next-page">
<a href="JavaScript:Void(0);" class="vf-pagination__link">
Next<span class="vf-u-sr-only"> page</span>
</a>
</li>
</ul>
</nav>
This repository is distributed with npm. After installing npm and yarn, you can install with this command.
$ yarn add --dev @visual-framework/vf-pagination
The style files included are written in Sass. If you're using a VF-core project, you can import it like this:
@import "@visual-framework/vf-pagination/index.scss";
Make sure you import Sass requirements along with the modules. You can use a project boilerplate or the vf-sass-starter
set-
style functions to cleaner version
File system location: components/vf-pagination
Find an issue on this page? Propose a change or discuss it.