Skip to content

Commit 42624e4

Browse files
committed
Improved the focus management from outside
1 parent b282516 commit 42624e4

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

src/Files.App.Controls/Omnibar/Omnibar.Events.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ private void Omnibar_SizeChanged(object sender, SizeChangedEventArgs e)
1717
private void AutoSuggestBox_GotFocus(object sender, RoutedEventArgs e)
1818
{
1919
IsFocused = true;
20-
21-
VisualStateManager.GoToState(CurrentSelectedMode, "Focused", true);
22-
VisualStateManager.GoToState(_textBox, "InputAreaVisible", true);
23-
24-
TryToggleIsSuggestionsPopupOpen(true);
2520
}
2621

2722
private void AutoSuggestBox_LostFocus(object sender, RoutedEventArgs e)
@@ -31,14 +26,6 @@ private void AutoSuggestBox_LostFocus(object sender, RoutedEventArgs e)
3126
return;
3227

3328
IsFocused = false;
34-
35-
if (CurrentSelectedMode?.ContentOnInactive is not null)
36-
{
37-
VisualStateManager.GoToState(CurrentSelectedMode, "CurrentUnfocused", true);
38-
VisualStateManager.GoToState(_textBox, "InputAreaCollapsed", true);
39-
}
40-
41-
TryToggleIsSuggestionsPopupOpen(false);
4229
}
4330

4431
private void AutoSuggestBox_KeyDown(object sender, KeyRoutedEventArgs e)

src/Files.App.Controls/Omnibar/Omnibar.Properties.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,27 @@ partial void OnCurrentSelectedModePropertyChanged(DependencyPropertyChangedEvent
2626

2727
ChangeMode(e.OldValue as OmnibarMode, newMode);
2828
}
29+
30+
partial void OnIsFocusedChanged(bool newValue)
31+
{
32+
if (CurrentSelectedMode is null)
33+
return;
34+
35+
if (newValue)
36+
{
37+
VisualStateManager.GoToState(CurrentSelectedMode, "Focused", true);
38+
VisualStateManager.GoToState(_textBox, "InputAreaVisible", true);
39+
}
40+
else
41+
{
42+
if (CurrentSelectedMode?.ContentOnInactive is not null)
43+
{
44+
VisualStateManager.GoToState(CurrentSelectedMode, "CurrentUnfocused", true);
45+
VisualStateManager.GoToState(_textBox, "InputAreaCollapsed", true);
46+
}
47+
}
48+
49+
TryToggleIsSuggestionsPopupOpen(newValue);
50+
}
2951
}
3052
}

src/Files.App.Controls/Omnibar/Omnibar.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ internal protected void FocusTextBox()
182182

183183
public bool TryToggleIsSuggestionsPopupOpen(bool wantToOpen)
184184
{
185-
if (wantToOpen && (!IsFocused || CurrentSelectedMode?.SuggestionItemsSource is null || (CurrentSelectedMode?.SuggestionItemsSource is IList collection && collection.Count is 0)))
185+
if (wantToOpen && (!IsFocused || CurrentSelectedMode?.SuggestionItemsSource is null || (CurrentSelectedMode?.SuggestionItemsSource is IList collection && collection.Count is 0)) ||
186+
_textBoxSuggestionsPopup is null)
186187
return false;
187188

188189
_textBoxSuggestionsPopup.IsOpen = wantToOpen;

0 commit comments

Comments
 (0)