Pagination jump scrolling and accessibility
Pagination jump scrolling and accessibility
I’ve been working with DT2 & BS5.3 and have an issue with pagination jump scrolling when used at the bottom of a layout, which I didn’t previously have in older versions. Clicking on new pages used to keep the pagination block at the bottom regardless of the page length, but now longer pages jump up and then scroll down to where it needs to be. So, the end result is the same, apart from some jumping around.
That led me to wonder what the correct method should be for accessibility but I can’t find a consensus. I successfully forced the next page to start to the top which to me makes more sense to me but not sure that is the correct way. I think the focus should be targeted in the top left th but I suppose some checking is then needed to make sure there aren’t any hidden columns. There are so many combinations I can think of so wondered if there are any examples of best practice?
This question has an accepted answers - jump to answer
Answers
Can you link to a page showing the issue please? It shouldn't be jumping the page scrolling around when clicking a paging button. Regarding focus, the browser's activeElement should remain the paging button, and not shift to a header cell on page change.
Allan
Thanks @allan for clarifying what should happen after clicking a paging button. I think it's because I'm used to clicking bottom paging on lots of forums etc that start at the top again. I suppose it's a subjective thing.
As for the scrolling problem, I wasn't sure if it's just with me or a wider problem. ChatGPT told me "This happens because DataTables 2 (with Bootstrap 5 integration) automatically focuses the first cell in the new page after draw, which causes the browser to scroll it into view.", and then offered me code fixes that didn't work! That obviously isn't the case.
I'll work on a stripped back version this weekend. The problem might be something I did in DT1 or the earlier Bootstrap that is causing the problem.
Yes, ChatGPT is just plain wrong there, which can be seen in this example if you change it to use Bootstrap 5 theming (menu in the top right) and then using the paging buttons.
Regarding skip to the top - use this plugin if you want that behaviour.
Allan
That's and odd one! I've not encountered that before... It appears to be coming from this CSS in Bootstrap 5:
Override that and it works as expected.
I think the focus being applied to the paging button is causing Chrome to scroll, and that setting in Bootstrap 5 makes it do it with a little animation.
Allan
Thanks @allan. I've fixed it by using your suggestion, and overriding the CSS with...