Skip to content

Commit

Permalink
fix(focus): [WASM] Adjust native focus application for TextBox
Browse files Browse the repository at this point in the history
Apply focus directly to inner TextBoxView to prevent it from bouncing back and forth.
  • Loading branch information
davidjohnoliver committed Mar 31, 2020
1 parent 1d29a90 commit c6a55b1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ public partial class TextBox : Control
private TextBoxView _textBoxView;

protected override bool IsDelegatingFocusToTemplateChild() => true; // _textBoxView
protected override bool RequestFocus(FocusState state) => FocusTextView();
partial void OnTextClearedPartial() => FocusTextView();
protected virtual bool FocusTextView() => FocusManager.FocusNative(_textBoxView);
internal bool FocusTextView() => FocusManager.FocusNative(_textBoxView);

private void UpdateTextBoxView()
{
Expand Down
5 changes: 5 additions & 0 deletions src/Uno.UI/UI/Xaml/Input/FocusManager.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ internal static bool FocusNative(UIElement element)
return false;
}

if (element is TextBox textBox)
{
return textBox.FocusTextView();
}

var command = $"Uno.UI.WindowManager.current.focusView({element.HtmlId});";
WebAssemblyRuntime.InvokeJS(command);

Expand Down

0 comments on commit c6a55b1

Please sign in to comment.