Menu

2,827 keyboard stops across our 79 pages, 1,608 of them the same footer, and no skip link anywhere
📰

2,827 keyboard stops across our 79 pages, 1,608 of them the same footer, and no skip link anywhere

DEV Community: nextjs·Daniel Pertu·about 14 hours ago
#lYsqpIh9
#devtonextjs#devto#dev#ccc#focus
Reading 0:00
15s threshold

You can query a page for focusable elements with a CSS selector, and you will get a number that is nearly right and occasionally a lie. The browser's sequential focus navigation order is its own thing: it respects tabindex , inert subtrees, visibility , shadow DOM and the order the elements actually sit in. So instead of querying, I pressed the key.

await page . cdp ( "Input.dispatchKeyEvent" , { type : "rawKeyDown" , key : "Tab" , code : "Tab" , windowsVirtualKeyCode : 9 } ) ; await page . cdp ( "Input.dispatchKeyEvent" , { type : "keyUp" , key : "Tab" , code : "Tab" , windowsVirtualKeyCode : 9 } ) ; const where = await page . evaluate ( ( ) => document . activeElement . textContent . trim ( ) ) ;

Enter fullscreen mode

Exit fullscreen mode

That is a real Tab press, in a real Chrome, on the live site . Do it in a loop, read document.activeElement and its computed style after each one, and you have the keyboard experience of a page as a list of rows.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.