I have two divs with a max-height and overflow auto. One div does not overflow and the other does. Scrollable divs can be scrolled with the keyboard, but the behavior is different between Firefox and Chrome:
- Firefox: The scrollable div is tab focusable even though I have not specified a tab index on it. The unscrollable div cannot be focused. This is a nice default behavior which I want.
- Chrome: The scrollable div cannot be tab focused unless I add
tabindex="0"to force it. In my use case the content of each div is user-generated and I do not know if it will overflow or not, so I can't just applytabindex="0"to all divs because it will make the unscrollable divs focusable which I do not want.
Note that Chrome allows the scrollable div to be scrolled if you click the div first then press arrow up/down, but this doesn't actually focus the div (the div does not become the document.activeElement). It seems Chrome remembers which element was last clicked. This is not a keyboard-only solution which I am looking for.
Basically I would like Chrome to work like Firefox in this scenario. Is this even possible? Maybe there's an accessibility setting in Chrome which enables this (I couldn't find one). How would keyboard-only users deal with this situation in Chrome?
div {
overflow: auto;
max-height: 50px;
border: 1px solid black;
margin: 10px 0;
}
div:focus {
outline: 2px solid blue;
}
<div>
Text does not overflow, not scrollable and should not receive tab focus.
</div>
<div>
Text overflows and should be tab focusable so that it can be scrolled with the keyboard.<br>
Text overflows and should be tab focusable so that it can be scrolled with the keyboard.<br>
Text overflows and should be tab focusable so that it can be scrolled with the keyboard.<br>
Text overflows and should be tab focusable so that it can be scrolled with the keyboard.
</div>