Skip to content

Commit

Permalink
perf: Improve Control focus performance
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Feb 8, 2024
1 parent 71bfb23 commit a2e1aab
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Uno.UI/UI/Xaml/Controls/Control/Control.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Uno.Disposables;
using Uno.UI;
using View = Microsoft.UI.Xaml.UIElement;
using Uno.UI.Xaml;

namespace Microsoft.UI.Xaml.Controls
{
Expand Down Expand Up @@ -49,7 +50,7 @@ partial void OnIsFocusableChanged()
{
var isFocusable = IsFocusable && !IsDelegatingFocusToTemplateChild();

SetAttribute("tabindex", isFocusable ? "0" : "-1");
WindowManagerInterop.SetIsFocusable(HtmlId, isFocusable);
}

private protected virtual bool IsDelegatingFocusToTemplateChild() => false;
Expand Down
5 changes: 5 additions & 0 deletions src/Uno.UI/UI/Xaml/Window/WindowManagerInterop.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,8 @@ internal static void WindowActivate()

internal static bool GetIsOverflowing(IntPtr htmlId)
=> NativeMethods.GetIsOverflowing(htmlId);
internal static void SetIsFocusable(IntPtr htmlId, bool isFocusable)
=> NativeMethods.SetIsFocusable(htmlId, isFocusable);

#region Pointers
[Flags]
Expand Down Expand Up @@ -1177,6 +1179,9 @@ internal static partial void ArrangeElement(

[JSImport("globalThis.Uno.UI.WindowManager.current.getIsOverflowing")]
internal static partial bool GetIsOverflowing(IntPtr htmlId);

[JSImport("globalThis.Uno.UI.WindowManager.current.setIsFocusable")]
internal static partial void SetIsFocusable(nint htmlId, bool isFocusable);
}
}
}
6 changes: 6 additions & 0 deletions src/Uno.UI/ts/WindowManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1790,6 +1790,12 @@ namespace Uno.UI {

return element.clientWidth < element.scrollWidth || element.clientHeight < element.scrollHeight;
}

public setIsFocusable(elementId: number, isFocusable: boolean) {
const element = this.getView(elementId) as HTMLElement;

element.setAttribute("tabindex", isFocusable ? "0" : "-1");
}
}

if (typeof define === "function") {
Expand Down

0 comments on commit a2e1aab

Please sign in to comment.