fix(wasm): Fix TextBox default alignment

This commit is contained in:
Youssef Victor 2024-07-24 11:07:48 +03:00
Родитель 78fd6628b1
Коммит a5eae5902a
4 изменённых файлов: 34 добавлений и 2 удалений

Просмотреть файл

@ -49,7 +49,11 @@ namespace Microsoft.UI.Xaml.Controls
}
public TextBoxView(TextBox textBox, bool isMultiline)
: base(isMultiline ? "textarea" : "input")
// We need to use textarea regardless of isMultiline
// because "input" native HTML element can't have its text top-aligned.
// For PasswordBox, it must be input. So, for now we can't match WinUI and it will
// remain center-aligned instead of top-aligned.
: base(textBox is PasswordBox ? "input" : "textarea")
{
IsMultiline = isMultiline;
_textBox = textBox;
@ -87,6 +91,11 @@ namespace Microsoft.UI.Xaml.Controls
HtmlInput += OnInput;
HtmlPaste += OnPaste;
if (!IsMultiline)
{
WindowManagerInterop.SetSingleLine(this);
}
SetTextNative(_textBox.Text);
}

Просмотреть файл

@ -14,6 +14,7 @@ using Windows.UI;
using Microsoft.UI.Xaml;
using System.Runtime.InteropServices.JavaScript;
using Microsoft.UI.Xaml.Controls;
namespace Uno.UI.Xaml
{
@ -31,6 +32,9 @@ namespace Uno.UI.Xaml
internal static void SetBodyCursor(string value)
=> NativeMethods.SetBodyCursor(value);
internal static void SetSingleLine(TextBoxView textBoxView)
=> NativeMethods.SetSingleLine(textBoxView.HtmlId);
/// <summary>
/// This method has two purposes:
/// - Initializes the window size before launch
@ -1111,6 +1115,9 @@ namespace Uno.UI.Xaml
[JSImport("globalThis.Uno.UI.WindowManager.setBodyCursor")]
internal static partial void SetBodyCursor(string value);
[JSImport("globalThis.Uno.UI.WindowManager.setSingleLine")]
internal static partial void SetSingleLine(IntPtr htmlId);
[JSImport("globalThis.Uno.UI.WindowManager.beforeLaunch")]
internal static partial string BeforeLaunch();

Просмотреть файл

@ -264,7 +264,12 @@ embed.uno-frameworkelement.uno-unarranged {
textarea {
resize: none;
overflow: hidden; /* Scrolling is handled by the parent ScrollViewer */
scrollbar-width: none;
}
textarea::-webkit-scrollbar {
width: 0;
background: transparent;
}
input::-ms-reveal,

Просмотреть файл

@ -183,6 +183,17 @@ namespace Uno.UI {
document.body.style.cursor = value;
}
static setSingleLine(htmlId: number): void {
const element = this.current.getView(htmlId);
if (element instanceof HTMLTextAreaElement) {
element.addEventListener("keydown", e => {
if (e.key === "Enter") {
e.preventDefault();
}
})
}
}
/**
* Reads the window's search parameters
*