electron / electron/electron

[Feature Request]: addChildView option to stop the added view grabbing focus

Open
#42,339 4 comments 7 reactions 0 assignees View on GitHub
component/accessibility enhancement :sparkles:
Dominant language
C++
Stars
123k
Forks
17.5k
Avg merge
14h 22m
Merged PRs (30d)
873

Description

### Preflight Checklist

- [X] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/main/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project adheres to.
- [X] I have searched the [issue tracker](https://www.github.com/electron/electron/issues) for a feature request that matches the one I want to file, without success.

### Problem Description

Whenever addChildView is called to add a WebContentsView to an existing BaseWindow, the webcontents will always grab the focus from whichever has it currently. It would be very useful to have an option to add the child view without losing focus from the current web contents.

Example: I have a child view with an input box which, as you type, creates another child view showing related contents. After the child view is created and addChildView called, the focus switches to the new child view and you can't continue typing into the original input box.

### Proposed Solution

Change addChildView from addChildView(view, [index]) to addChildView(view, [options]) where
```
options = {
index?:number, // Default is the end of the list
focus?:boolean // Default is true
}
```
For backwards compatibility, check if options is a number and behave as it does currently.

### Alternatives Considered

I've tried a number of alternatives, such as setting the parent BaseWindow with setFocusable(false) before adding the child view but this move other windows above the current and also loses focus.

### Additional Information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.