I am trying to optimize the accessibility of my shiny app for users that use screen readers. This involves making sure the app is navigable using the keyboard (mainly the tab key). I have run into a problem with the navlistPanel() ui element as the tabs are not keyboard-focusable. I think this may be due to the elements having a tabindex of -1. How can I override this behavior and make the navigation menu keyboard accessible?
Usually I would have recommended using htmltools::tagQuery or tagAppendAttributes().
However, in this case tagQuery(tabPanel("Tab 2", "Second content")) can only access the div tags not the relevant a tags because they are only generated when the server is up.
We can use JS directly instead to modify the tabindex attribute:
I could tab through the links on startup, but once I selected a different link, the previous one would revert to a tabindex of -1 and couldn't be tabbed again.