Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overlay2 displays unwanted focus outline on initial render #7195

Open
ggdouglas opened this issue Jan 23, 2025 · 0 comments
Open

Overlay2 displays unwanted focus outline on initial render #7195

ggdouglas opened this issue Jan 23, 2025 · 0 comments

Comments

@ggdouglas
Copy link
Contributor

ggdouglas commented Jan 23, 2025

Description

When using the <Overlay2> component with isOpen={true}, a 2px blue line (focus outline) appears at the top of the page during the initial render, before any user interaction (e.g., clicks). This happens even though FocusStyleManager.onlyShowFocusOnTabs() is present.

Example Code:

import { FocusStyleManager, Overlay2, Classes } from "@blueprintjs/core";

FocusStyleManager.onlyShowFocusOnTabs();

const App = () => (
  <Overlay2 isOpen={true} backdropClassName={Classes.POPOVER_BACKDROP}>
    {/* Overlay content */}
  </Overlay2>
);

The problem seems to stem from FocusStyleManager only initializing and applying the .bp5-focus-disabled class to the root document after the first mousedown interaction. Until then, focus styles are still applied to focused elements.

Image

public start() {
this.container.addEventListener("mousedown", this.handleMouseDown);
this.isRunning = true;

Environment

  • Package version(s): 5.16.4
  • Browser name and version: Chrome 131.0.6778.265

Code Sandbox

Minimal repro here (visible in debug preview)

Note this bug is easier to reproduce when toggling the "Emulate a focused page" setting in tools, rendering -> check "emulate a focused" page

Image

Steps to reproduce

  1. Set up FocusStyleManager:
    Include FocusStyleManager.onlyShowFocusOnTabs() in your application.

  2. Render Overlay2:
    Render an <Overlay2> component with isOpen={true}:

    <Overlay2 isOpen={true} backdropClassName={Classes.POPOVER_BACKDROP}>
      {/* Overlay content */}
    </Overlay2>
  3. Load the page:
    Load the page without any prior interaction (do not click or tap).

  4. Observe the issue:
    Notice a blue focus outline at the top of the page.

    Tip: To reproduce the issue more reliably, enable "Emulate a focused page" in Chrome DevTools:

    • Open DevTools
    • Go to Rendering tab
    • Check Emulate a focused page

Expected behavior

The focus outline (blue border) should not be displayed upon initial render due to FocusStyleManager.onlyShowFocusOnTabs(), which should suppress focus styles unless the user is navigating via keyboard.

Actual behavior

A blue focus outline appears at the top of the page on initial load before any user interaction.

Screenshots:

Focus outline visible at the top:

Image

Possible solution

Adjust FocusStyleManager to apply the .bp5-focus-disabled class to the document immediately on page load, not after the first mousedown event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant