Skip to content

Add SurrenderFocusOn option#7471

Merged
lucasmerlin merged 8 commits intomainfrom
lucas/surrender-focus-on
Aug 21, 2025
Merged

Add SurrenderFocusOn option#7471
lucasmerlin merged 8 commits intomainfrom
lucas/surrender-focus-on

Conversation

@lucasmerlin
Copy link
Copy Markdown
Collaborator

  • I have followed the instructions in the PR template

On touch devices you don't want the keyboard to disappear when scrolling, so this PR adds a SurrenderFocusOn enum to configure on what interaction to surrender focus.

@github-actions
Copy link
Copy Markdown

Preview available at https://egui-pr-preview.github.io/pr/7471-lucassurrender-focus-on
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

@lucasmerlin lucasmerlin added feature New feature or request egui labels Aug 21, 2025
@lucasmerlin lucasmerlin merged commit bf981b8 into main Aug 21, 2025
47 checks passed
@lucasmerlin lucasmerlin deleted the lucas/surrender-focus-on branch August 21, 2025 15:45
@juancampa
Copy link
Copy Markdown
Contributor

juancampa commented Jan 31, 2026

Let's, make Clicks the default

Defaulting to SurrenderFocusOn::Clicks makes egui inconsistent with other platforms. Just wanted to point this out somewhere in case other people hit similar issues.

At least on Chrome (MacOS) as well as some MacOS apps, the behavior seems to be to surrender focus on press (i.e. mouse down), not click.

I found this because it also makes it hard to pass the focus to a new widget. E.g.

if ui.button("Edit").clicked() {
  editing = true;
  
  // Pass focus to the TextEdit below
  ui.memory_mut(|mem| mem.request_focus(ID));
}

if editing {
  let response = TextEdit::singleline(...).id(ID).show(ui);
  
  assert!(response.has_focus()); <--- Just to illustrate the issue
}

In the code above, TextEdit immediately surrenders its focus because the button click is detected as a "clicked elsewhere" at the end of get_response.

Having said that, I can see how Clicks is better in some cases (resize a panel or move a slider while editing text), but it might be surprising for many users.

Masterchef365 pushed a commit to Masterchef365/egui that referenced this pull request Apr 3, 2026
* [X] I have followed the instructions in the PR template

On touch devices you don't want the keyboard to disappear when
scrolling, so this PR adds a `SurrenderFocusOn` enum to configure on
what interaction to surrender focus.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

egui feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants