Skip to content

Commit e44d7cd

Browse files
committed
Don't add tabindex to interactive elements
1 parent 9b264b3 commit e44d7cd

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/index.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,15 @@ function getElAndScroll() {
5050
// update focus to where the page is scrolled to
5151
// unfortunately this doesn't work in safari (desktop and iOS) when blur() is called
5252
let originalTabIndex = element.getAttribute('tabindex');
53-
if (originalTabIndex === null) element.setAttribute('tabindex', -1);
53+
if (originalTabIndex === null && !isInteractiveElement(element)) {
54+
element.setAttribute('tabindex', -1);
55+
}
5456
element.focus({ preventScroll: true });
55-
if (originalTabIndex === null) {
56-
if (!isInteractiveElement(element)) {
57-
// for some reason calling blur() in safari resets the focus region to where it was previously,
58-
// if blur() is not called it works in safari, but then are stuck with default focus styles
59-
// on an element that otherwise might never had focus styles applied, so not an option
60-
element.blur();
61-
}
62-
57+
if (originalTabIndex === null && !isInteractiveElement(element)) {
58+
// for some reason calling blur() in safari resets the focus region to where it was previously,
59+
// if blur() is not called it works in safari, but then are stuck with default focus styles
60+
// on an element that otherwise might never had focus styles applied, so not an option
61+
element.blur();
6362
element.removeAttribute('tabindex');
6463
}
6564

0 commit comments

Comments
 (0)