Skip to content

Code Quality: Prevent mode button from removing Omnibar focus #17242

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

Merged
merged 3 commits into from
Jul 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/Files.App.Controls/Omnibar/Omnibar.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ private void AutoSuggestBox_GettingFocus(UIElement sender, GettingFocusEventArgs

private void AutoSuggestBox_LosingFocus(UIElement sender, LosingFocusEventArgs args)
{
if (args.NewFocusedElement is Button && IsModeButtonPressed)
{
IsModeButtonPressed = false;
args.TryCancel();
// Prevent the TextBox from losing focus when the ModeButton is focused
if (args.NewFocusedElement is not Button button ||
args.InputDevice is FocusInputDeviceKind.Keyboard ||
button.Name.ToString() != "PART_ModeButton")
return;
}

args.TryCancel();
}

private void AutoSuggestBox_GotFocus(object sender, RoutedEventArgs e)
Expand Down
3 changes: 0 additions & 3 deletions src/Files.App.Controls/Omnibar/Omnibar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ public partial class Omnibar : Control

private WeakReference<UIElement?> _previouslyFocusedElement = new(null);

// NOTE: This is a workaround to keep Omnibar's focus on a mode button being clicked
internal bool IsModeButtonPressed { get; set; }

// Events

public event TypedEventHandler<Omnibar, OmnibarQuerySubmittedEventArgs>? QuerySubmitted;
Expand Down
1 change: 1 addition & 0 deletions src/Files.App.Controls/Omnibar/Omnibar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
<Button
x:Name="PART_ModeButton"
Width="{StaticResource OmnibarModeDefaultClickAreaWidth}"
Height="{StaticResource OmnibarModeDefaultHeight}"
Margin="1"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
Expand Down
1 change: 0 additions & 1 deletion src/Files.App.Controls/Omnibar/OmnibarMode.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ private void ModeButton_Click(object sender, RoutedEventArgs e)
if (_ownerRef is null || _ownerRef.TryGetTarget(out var owner) is false || owner.CurrentSelectedMode == this)
return;

owner.IsModeButtonPressed = true;
owner.CurrentSelectedMode = this;
}
}
Expand Down
Loading