I would like to change the focus in the DOM based on the browser's own calculations of which element is the next focusable element.
I understand that...
- Keypresses can't be triggered in most browsers by JavaScript (see https://stackoverflow.com/a/32429197/1766230), so we can't trigger the Tab key to go to the next focused element (nor would we want to since the keypress event could be overridden).
- We could write some code to find all links/inputs/etc., find which one is currently focused, and trigger a focus on the next one. ... but that seems like it is just duplicating logic that is natively in the browser somewhere.
My question is: Can we utilize the browser's own logic for determining the next focusable element, and focusing on it?