pagination: activate page items with Space key#304
Conversation
* Fixes page items not being activated by the "Space" key when focused via keyboard navigation. (closes inveniosoftware#295) * Page items are rendered by semantic-ui-react as anchors without href, with keyboard activation wired up manually for "Enter" only. Per the ARIA APG button pattern, elements behaving as buttons must be activatable with both "Enter" and "Space". * Adds a custom pageItem render function that invokes the injected onClick on "Space" keydown, prevents the default page scroll, and adds role="button" for assistive technologies.
* Fixes page items not being activated by the "Space" key when focused via keyboard navigation. (closes inveniosoftware#295) * Page items are rendered by semantic-ui-react as anchors without href, with keyboard activation wired up manually for "Enter" only. Per the ARIA APG button pattern, elements behaving as buttons must be activatable with both "Enter" and "Space". * Adds a custom pageItem render function that invokes the injected onClick on "Space" keydown, prevents the default page scroll, and adds role="button" for assistive technologies.
…imDumbledodge/react-searchkit into fix-pagination-space-key-a11y
|
Hello, thank you very much for the fix. @monotasker given that you were reporting the issue, could you please have a quick look to it? |
|
I tested it out locally and it works smoothly. And the mechanism for adding the keystroke listener makes sense. Looks great. The tests all pass for me locally, so I believe @ntarocco is right. Please remove the package-lock.json from the PR (so that the tests will pass) and we should be able to merge it. |
|
I think your suggestion about adding handling to the next/prev buttons for the spacebar press is also important. So if you can submit another PR with that remediation, that would be very good. |
monotasker
left a comment
There was a problem hiding this comment.
I tested out the change and it works nicely. Addresses the a11y issue well.
|
@ntarocco, I don't have merge privileges and I'm not sure if there's someone else I should request review from who does? |
❤️ Thank you for your contribution!
Description
Fixes #295
Root cause
Pagination page items are rendered by semantic-ui-react's
Paginationas anchors withouthrefand without an explicitrole:An anchor without
hrefhas no native keyboard activation, so semantic-ui-react makes it focusable withtabindex="0"and wires up keyboard activation manually inPaginationItem. However, only "Enter" is handled:Since these items behave as buttons (they trigger an action rather than navigate to a URL), the ARIA APG button pattern applies: they should be activatable with both "Enter" and "Space".
Fix
The root cause lives in semantic-ui-react, but it can be remediated on the react-searchkit side. This PR passes a custom render function to the
pageItemshorthand that:keydownby invoking the sameonClickthat semantic-ui-react injects into the item props, mirroring its existing "Enter" handlingpreventDefault()to avoid the default page scroll on "Space"role="button"so the announced semantics match the behavior for assistive technologiesMouse and "Enter" activation are unchanged.
Scope
The fix is intentionally scoped to page items, as reported in the issue. The first/prev/next/last arrow items share the same underlying limitation, but customizing them through the shorthand render function drops their default content (icons), so extending the fix to them would require rebuilding those defaults. Happy to address that in a follow-up if there is interest.
Note: using an item shorthand render function triggers a semantic-ui-react v3 deprecation warning in the test output. v3 was never released, this repo pins v2, and there is no alternative API to customize pagination items.
How to verify
docker-compose upinsrc/demos/opensearch/docker, load the demo data,npm start)Checklist
Ticks in all boxes and 🟢 on all GitHub actions status checks are required to merge:
Frontend
Reminder
By using GitHub, you have already agreed to the GitHub’s Terms of Service including that: