Skip to content

Commit

Permalink
Merge pull request unoplatform#7512 from unoplatform/dev/xygu/2021112…
Browse files Browse the repository at this point in the history
…3/wasm-textbox-hitbox

fix(textbox): caret cursor and click focus area on wasm
  • Loading branch information
Xiaoy312 authored Dec 3, 2021
2 parents 66fa609 + 775e854 commit b931660
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -848,5 +848,26 @@ private static PointF GetPixelPositionWithColor(ScreenshotInfo screenshotInfo, I

throw new InvalidOperationException($"Color {expectedColor} was not found.");
}

[Test]
[AutoRetry]
[ActivePlatforms(Platform.Browser)]
public void TextBox_WithPadding_Focus()
{
Run("UITests.Windows_UI_Xaml_Controls.TextBox.TextBox_WithPadding_Focus");

const string Text = "asdqwe";

foreach (var marked in new[] { "textBox1", "textBox2" })
{
// tap near the edge (area pushed/occupied by TextBox.Padding)
var rect = _app.GetPhysicalRect(marked);
_app.TapCoordinates(rect.Right - 5, rect.Bottom - 5);
_app.Wait(seconds: 1);

_app.EnterText(Text);
_app.WaitForText(marked, Text, timeout: TimeSpan.FromSeconds(20));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void TestTextBoxReleaseOutFocused()

[Test]
[AutoRetry]
[ActivePlatforms(Platform.Android, Platform.iOS)] // For touch, focus should be set only when released outside of TextBox
[ActivePlatforms(/*Platform.Android, */Platform.iOS)] // For touch, focus should be set only when released outside of TextBox
public void TestTextBoxReleaseOutUnfocused()
{
Run("UITests.Shared.Windows_UI_Input.VisualStatesTests.TextBox_VisualStates");
Expand Down
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 @@ -1885,6 +1885,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\TextBox\TextBox_WithPadding_Focus.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\TextBox\TextBox_Wrapping.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -5663,6 +5667,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\TextBox\TextBox_TextChanging.xaml.cs">
<DependentUpon>TextBox_TextChanging.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\TextBox\TextBox_WithPadding_Focus.xaml.cs">
<DependentUpon>TextBox_WithPadding_Focus.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\TextBox\TextBox_Wrapping.xaml.cs">
<DependentUpon>TextBox_Wrapping.xaml</DependentUpon>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<UserControl
x:Class="UITests.Windows_UI_Xaml_Controls.TextBox.TextBox_WithPadding_Focus"
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.TextBox"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">

<StackPanel Spacing="8">
<TextBox x:Name="textBox1" Padding="24" />
<TextBox x:Name="textBox2" Padding="24">
<TextBox.Template>
<ControlTemplate>
<Grid Background="{TemplateBinding Background}"
Padding="{TemplateBinding Padding}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ScrollViewer x:Name="ContentElement"
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}"
IsTabStop="False"
IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}"
VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
VerticalAlignment="Bottom"
ZoomMode="Disabled"
AutomationProperties.AccessibilityView="Raw">
<ScrollViewer.RenderTransform>
<CompositeTransform x:Name="ContentElement_CompositeTransform" />
</ScrollViewer.RenderTransform>
</ScrollViewer>
</Grid>
</ControlTemplate>
</TextBox.Template>
</TextBox>
</StackPanel>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Uno.UI.Samples.Controls;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

namespace UITests.Windows_UI_Xaml_Controls.TextBox
{
[SampleControlInfo(nameof(TextBox), nameof(TextBox_WithPadding_Focus))]
public sealed partial class TextBox_WithPadding_Focus : UserControl
{
public TextBox_WithPadding_Focus()
{
this.InitializeComponent();
}
}
}
9 changes: 9 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,15 @@ protected override void OnPointerReleased(PointerRoutedEventArgs args)
args.Handled = true;
}

protected override void OnTapped(TappedRoutedEventArgs e)
{
base.OnTapped(e);

OnTappedPartial();
}

partial void OnTappedPartial();

/// <inheritdoc />
protected override void OnKeyDown(KeyRoutedEventArgs args)
{
Expand Down
7 changes: 7 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ partial void InitializePropertiesPartial()
{
AddHandler(PointerReleasedEvent, (PointerEventHandler)OnHeaderClick, true);
}

SetStyle("cursor", "text");
}

partial void OnTappedPartial()
{
FocusTextView();
}

private void OnHeaderClick(object sender, object args)
Expand Down

0 comments on commit b931660

Please sign in to comment.