nrkno / core-components

Accessible and lightweight Javascript components
https://static.nrk.no/core-components/latest/
MIT License
117 stars 10 forks source link

core-dialog: Impossible to focus first or last link in dialog using tab #499

Closed esseb closed 3 years ago

esseb commented 4 years ago

Testcase: https://codesandbox.io/s/core-dialog-impossible-to-focus-first-or-last-link-in-dialog-using-tab-lo8hp

When the first or last focusable element in a core-dialog is a link it is impossible to focus using tab or shift + tab.

In addition if the first focusable element in a core-dialog is a link it does not get autofocused when the dialog is opened.

This is because the isVisible() test in core-dialog.js checks if el.clientWidth and el.clientHeight is greater than 0 to determine if the element is visible, but this is always 0 for inline elements such as links according to the spec.

I can make a PR and maybe use el.getBoundingClientRect() instead but I'm not entirely sure why this function checks el.clientWidth and el.clientHeight. Even buttons can have width/height/padding of 0 and still be interactive as far as I know, especially without overflow: hidden, although this is not a good practice of course.