Skip to content
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

fix(textbox): losing focus on PointerUp when inside a Popup on WASM #18887

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions src/SamplesApp/UITests.Shared/UITests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\AutoSuggestBoxTests\AutoSuggestBox_PopupFocus.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\AutoSuggestBoxTests\AutoSuggestBox_Icons.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -6558,6 +6562,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\AutoSuggestBoxTests\AutoSuggestBox_Description.xaml.cs">
<DependentUpon>AutoSuggestBox_Description.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\AutoSuggestBoxTests\AutoSuggestBox_PopupFocus.xaml.cs">
<DependentUpon>AutoSuggestBox_PopupFocus.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\AutoSuggestBoxTests\AutoSuggestBox_Icons.xaml.cs">
<DependentUpon>AutoSuggestBox_Icons.xaml</DependentUpon>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<Page
x:Class="UITests.Windows_UI_Xaml_Controls.AutoSuggestBoxTests.AutoSuggestBox_PopupFocus"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Windows_UI_Xaml_Controls.AutoSuggestBoxTests"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<StackPanel>
<Button Content="Click me">
<Button.Flyout>
<Flyout>
<StackPanel>
<TextBlock>
Repro Steps:
ramezgerges marked this conversation as resolved.
Show resolved Hide resolved
<LineBreak/>
1. Click on the TextBox below. The textbox should look focused
<LineBreak/>
(i.e.light blue bottom border).
<LineBreak/>
2. Type the character "T". A suggestions list should pop up
<LineBreak/>
with a single item, "test".
</TextBlock>
<AutoSuggestBox PlaceholderText="type some text">
<AutoSuggestBox.Items>
<x:String>test</x:String>
</AutoSuggestBox.Items>
</AutoSuggestBox>
<TextBox />
</StackPanel>
</Flyout>
</Button.Flyout>
</Button>
</StackPanel>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Uno.UI.Samples.Controls;
using Microsoft.UI.Xaml.Controls;

namespace UITests.Windows_UI_Xaml_Controls.AutoSuggestBoxTests;

[Sample("AutoSuggestBox", IsManualTest = true)]
public sealed partial class AutoSuggestBox_PopupFocus : Page
{
public AutoSuggestBox_PopupFocus()
{
this.InitializeComponent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ protected override void OnPointerReleased(PointerRoutedEventArgs args)

private static bool ScrollContentControl_SetFocusOnFlyoutLightDismissPopupByPointer(UIElement pScrollContentControl)
{
#if __CROSSRUNTIME__
ramezgerges marked this conversation as resolved.
Show resolved Hide resolved
if ((pScrollContentControl as ScrollViewer)?.DisableSetFocusOnPopupByPointer ?? false)
{
return false;
}
#endif

PopupRoot? pPopupRoot = null;
Popup? pPopup = null;

Expand Down
11 changes: 11 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/ScrollViewer/ScrollViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,17 @@ public double HorizontalOffset
);
#endregion

#if __CROSSRUNTIME__
ramezgerges marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>
/// This is specifically added for ScrollViewers inside TextBoxes and specifically for WASM
/// On WASM, a click on a TextBox inside a popup shifts focus to the Popup instead of the TextBox
/// as a result of ScrollContentControl_SetFocusOnFlyoutLightDismissPopupByPointer.
/// This is only a problem on WASM because we don't capture the pointer when pressing inside a TextBox
/// <seealso cref="TextBox.IsPointerCaptureRequired"/>.
/// </summary>
internal bool DisableSetFocusOnPopupByPointer { get; set; }
#endif

private readonly SerialDisposable _sizeChangedSubscription = new SerialDisposable();

#pragma warning disable 649 // unused member for Unit tests
Expand Down
8 changes: 7 additions & 1 deletion src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.Uno.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public bool IsPointerCaptureRequired
new FrameworkPropertyMetadata(
// We should not capture the pointer on WASM by default because it would prevent the user from scrolling through text on selection.
// See https://github.com/unoplatform/uno/pull/16982, https://issues.chromium.org/issues/344491566
false));
false, static (dO, args) =>
{
if (((TextBox)dO)._contentElement is ScrollViewer sv)
{
sv.DisableSetFocusOnPopupByPointer = !(bool)args.NewValue;
}
}));
ramezgerges marked this conversation as resolved.
Show resolved Hide resolved
#endif
}
4 changes: 4 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ private protected override void OnLoaded()
scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled; // The template sets this to Hidden
scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; // The template sets this to Hidden
}

#if __WASM__
scrollViewer.DisableSetFocusOnPopupByPointer = !IsPointerCaptureRequired;
#endif
#endif
}
}
Expand Down
Loading