-
-
Notifications
You must be signed in to change notification settings - Fork 235
Description
Describe the bug
When using OverlayScrollbars, the library forcibly adds tabindex="-1" to the scrollbar viewport element. As a result, clicking any empty (non-interactive) area inside the content wrapped by OverlayScrollbars changes focus unexpectedly: document.activeElement becomes the viewport instead of the default document.body. This breaks logic that relies on the browser’s default focus behavior (e.g., global keyboard shortcuts, blur handlers, focus traps).
To Reproduce
Steps to reproduce the behavior:
- Initialize OverlayScrollbars on a container with mostly non-focusable content.
- Ensure no inner control is focused (focus is on
bodyor a control outside the scrollable area). - Click on an empty spot inside the scrollable content (not on links/inputs).
- Observe in console that
document.activeElementswitches to the OverlayScrollbars viewport (the element withtabindex="-1"), instead of staying onbody.
Expected behavior
Clicking on non-interactive, empty space inside the scrollable content should not change active element. The default behavior should be preserved: document.activeElement should remain document.body (or the previously focused element). OverlayScrollbars should avoid stealing focus implicitly—e.g., by not applying a tabindex that causes viewport active on click, or by ensuring clicks on empty areas do not move active element to the viewport.
Examples
Observe in console:
Environment
- OverlayScrollbars version: "overlayscrollbars": "2.12.0", "overlayscrollbars-react": "0.5.6"
- Used Operating System(s): win11
- Used Browser(s) (with version): 140.0.7339.128 (Official Build) (64-bit)
Additional context
Focus management APIs
MDN