Paginator
A Paginator allows for navigation across a range of pages of related content, and also indicates a user's position within that range. Visage provides a standard set of controls, leaving it up to the particular page to implement the pagination logic behind them.
Paginator with buttons
<Paginator visuallyHiddenText="Pagination"><PaginatorButtonvariant="previous"href="#"visuallyHiddenText="Previous Page"disabled/><PaginatorStep visuallyHiddenText="Page 1">1</PaginatorStep><PaginatorStep active visuallyHiddenText="Page 2">2</PaginatorStep><PaginatorEllipses /><PaginatorStep visuallyHiddenText="Page 27">27</PaginatorStep><PaginatorStep disabled visuallyHiddenText="Page 28">28</PaginatorStep><PaginatorButton variant="next" href="#" visuallyHiddenText="Next Page" /></Paginator>
Paginator with input
<Paginator visuallyHiddenText="Pagination"><PaginatorButtonvariant="previous"href="#"visuallyHiddenText="Previous Page"disabledonClick={() => console.log('Clicked previous')}/><PaginatorInputvisuallyHiddenText="Go to page"onChange={e => console.log('Changed to page ' + e.target.value)}/><PaginatorLabel>of 35</PaginatorLabel><PaginatorButtonvariant="next"href="#"visuallyHiddenText="Next Page"onClick={() => console.log('Clicked next')}/></Paginator>
<!-- the aria-label values on all the elements must be localized! --><nav class="paginator" role="navigation" aria-label="Pagination"><ahref="someurl"class="paginator-button-previous"aria-label="Previous Page"></a><!-- can be a <button> tag, if appropriate --><inputtype="number"class="stylized-input paginator-input"value="NN"aria-label="Go to page"aria-describedby="examplePaginatorMax"/><span class="paginator-max" id="examplePaginatorMax">of NN</span><a class="paginator-button-next" aria-label="Next Page"></a></nav>
Components
Paginator
Prop | Type | Default | Description |
---|---|---|---|
visuallyHiddenText | string | required | Text that will be visually hidden, but read aloud by screen-reader. |
All other props are forwarded to the element specified in thecomponent
prop(default: <div/>
)
PaginatorButton
Prop | Type | Default | Description |
---|---|---|---|
variant | "next" | "previous" | required | The visual style of the Button |
visuallyHiddenText | string | required | Text that will be visually hidden, but read aloud by screen-reader. |
All other props are forwarded to the element specified in thecomponent
prop(default: <div/>
)
PaginatorInput
Prop | Type | Default | Description |
---|---|---|---|
visuallyHiddenText | string | required | Text that will be visually hidden, but read aloud by screen-reader. |
All other props are forwarded to the element specified in thecomponent
prop(default: <div/>
)
PaginatorLabel
PaginatorLabel
has no props of its own
All props are forwarded to the element specified in thecomponent
prop(default: <div/>
)
PaginatorStep
Prop | Type | Default | Description |
---|---|---|---|
active | boolean | false | Applies active page styling |
visuallyHiddenText | string | required | Text that will be visually hidden, but read aloud by screen-reader. |
All other props are forwarded to the element specified in thecomponent
prop(default: <a/>
)
PaginatorEllipses
PaginatorEllipses
has no props of its own
All props are forwarded to the element specified in thecomponent
prop(default: <div/>
)
Guidelines
Developer Guidelines
Paginator is a simple set of controls with no actual pagination logic behind them. The page that uses it will need to:
attach the URLs and/or handle any clicks to the Previous and Next buttons
attach a change handler to the input field, taking the user to the specified page when the input's value is changed
Paginator buttons can use either
<a>
or<button>
tags; the ReactPaginatorButton
component will default to<a>
tags. Use<a>
tags if a click takes the user to a new page; use<button>
tags if a click loads new content into the same page.If the user is at the first or last page, the Previous or Next button should be disabled accordingly:
In React: add the
disabled
prop to thePaginatorButton
.In vanilla JS: if your Paginator use
<a>
tags, change the Prev/Next button to a<span>
tag and add classpaginator-button-disabled
. If your Paginator uses<button>
tags, disable the button as you normally would for a button, by adding the attributedisabled="disabled"
.
Accessibility Guidelines
The buttons and the text input need additional text to guide the user as to their function.
In React, use the
visuallyHiddenText
prop to provide guidance (as shown in the code example above).In vanilla JS, use
aria-label
andaria-describedby
attributes (as show in the code example above). Anyaria-label
values will need to be localized, since they will be presented to the user by screen readers and assistive devices.