Modalizer: clicking back into a trap-focus popup after programmatic focus escape causes immediate blur
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
- Open a popover with
trapFocusenabled (e.g. Fluent UI<Popover trapFocus>),
focus is inside it. - Call
element.focus()on an element outside the popover from application
code (e.g. a keyboard shortcut handler moves focus to a sidebar element). - The popover remains visible. Tabster calls
setActive(undefined)because the
target is not inside any modalizer — the popup's modalizer is now deactivated. - Click on an input inside the still-visible popover.
- Expected: input receives and retains focus.
- 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→ falsemodalizer && 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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