Skip to content

Forcing tabindex to -1 on a scrollbar viewport container allows it to become an active element #732

@siarhei-epam

Description

@siarhei-epam

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:

  1. Initialize OverlayScrollbars on a container with mostly non-focusable content.
  2. Ensure no inner control is focused (focus is on body or a control outside the scrollable area).
  3. Click on an empty spot inside the scrollable content (not on links/inputs).
  4. Observe in console that document.activeElement switches to the OverlayScrollbars viewport (the element with tabindex="-1"), instead of staying on body.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions