microsoft / microsoft/tabster

Modalizer: clicking back into a trap-focus popup after programmatic focus escape causes immediate blur

Open
#501 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
165
Forks
42
Avg merge
1d 11h
Merged PRs (30d)
9

Description

Summary

When focus is programmatically moved outside an active modalizer (e.g. via
element.focus() from application code), and the user then clicks on an
element inside that same modalizer, the element briefly receives focus and then
immediately loses it.

Tabster version

8.7.0

Steps to reproduce

  1. Open a popover with trapFocus enabled (e.g. Fluent UI <Popover trapFocus>),
    focus is inside it.
  2. Call element.focus() on an element outside the popover from application
    code (e.g. a keyboard shortcut handler moves focus to a sidebar element).
  3. The popover remains visible. Tabster calls setActive(undefined) because the
    target is not inside any modalizer — the popup's modalizer is now deactivated.
  4. Click on an input inside the still-visible popover.
  5. Expected: input receives and retains focus.
  6. Actual: input gets focus for ~100ms then immediately loses it.

Root cause

Step A — programmatic focus deactivates the modalizer.
isFocusedProgrammatically === true + target outside any modalizer → setActive(undefined)
this.activeId = undefined.

Step B — the user click is not recognized as targeting the active modal.
isFocusedProgrammatically === false, modalizer.userId !== activeId (undefined),
none of the allow-conditions pass → _restoreModalizerFocus is scheduled in 100ms.

Step C_restoreModalizerFocus blurs the input.
The early-exit guard:

if (!modalizer && !activeId || modalizer && activeId === modalizer.userId) {
    return;
}

With modalizer truthy (input is inside the popup) and activeId === undefined:

  • !modalizer && !activeId → false
  • modalizer && activeId === modalizer.userId → false

Neither exits. findFirst({ useActiveModalizer: true }) returns undefined
(no active modalizer to search within) → falls through to:

outsideElement.blur();  // blurs the input the user just clicked

Workaround

Block the programmatic focus movement before it happens (e.g. prevent keyboard
shortcuts from firing while a trap-focus popup is open). Incomplete as a general
solution since any element.focus() call can trigger the same deactivation.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the focus sequence with a trap-focus popup, then trace setActive(undefined), _restoreModalizerFocus, and findFirst({ useActiveModalizer: true }). Verify that clicking back into the still-visible popup after programmatic focus escape keeps the clicked input focused and does not trigger the delayed blur.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
accessibility, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.