question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Regression: Focus scope API no longer accessible

See original GitHub issue

Describe the bug The focus scope API (FocusManager.Scope, FocusManager.GetFocusedElement(IFocusScope)) is no longer accessible as of #11407, which is breaking our app/UI libraries.

Our current app implements ToolBars, RoutedCommands (similar to WPF), a “Quick Launch Box”/“Command palette” and docking windows (like Visual Studio). The application depends on focus scopes. Details:

  • Windows, Menus, ToolBarTrays and the “Quick Launch Box” implement IFocusScope.
  • The Avalonia FocusManager keeps track of the last focused element in each focus scope.
  • Common commands (Cut, Copy, Paste, etc.) are implemented as RoutedCommands. Similar to WPF’s ApplicationCommands.
  • When a command in Menu, ToolBar, or “Quick Launch Box” is triggered it needs to be routed to the previously focused element. This is done by determining the current focus scope (FocusManager.Scope), finding the parent focus scope, and routing the event to the last focused element (FocusManager.GetFocusedElement(IFocusScope)).
  • After the command is executed the toolbar item or “Quick Launch Box” needs to give up the focus and move it back to the previously focused element.

To Reproduce Third-party apps or UI control libraries can no longer access FocusManager. The focus scope API is not exposed in IFocusManager.

Expected behavior Third-party apps or UI control libraries should have a way to access focus scopes.

Solution This can be solved by pulling the following members from FocusManager into IFocusManager:

/// <summary>
/// Gets the current focus scope.
/// </summary>
IFocusScope? Scope { get; }

/// <summary>
/// Gets the currently focused element in the given focus scope.
/// </summary>
public IInputElement? GetFocusedElement(IFocusScope scope);

Focus scopes are an important concept needed for command routing in complex scenarios and for porting WPF applications to Avalonia UI. I strongly recommend keeping the functionality and not removing it as part of any future changes (e.g. #7607).

Screenshots n.a.

Desktop (please complete the following information):

  • OS: Windows
  • Version 11.0.0-rc1.1

Additional context n.a.

Issue Analytics

  • State:closed
  • Created 4 months ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
kekekekscommented, Jun 2, 2023

IIRC there were hard to resolve issues with the way focus scopes are implemented. There are some plans to have a full WPF-like implementation, but no ETA yet.

1reaction
maxkatz6commented, Jun 1, 2023

Either way, it doesn’t sound like something that can’t be done with existing API without making it more complex:

  • it’s possible to get the currently focused element
  • it’s possible to track focus movements globally, i.e. static GotFocus.Raised.Subscribe()

But I might be missing something as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Automated Accessibility Part 3: Regression Tests
Accessibility regression tests can help build a culture where tests MUST include accessibility as part of functional UI testing, and encourage ...
Read more >
REST API Testing Strategy: What Exactly Should You Test?
The API layer of any application is one of the most crucial software components. Here's a technical look at how we test our...
Read more >
Top 18 Most Common AngularJS Developer Mistakes
No longer can AngularJS developers ignore memory consumption, because it will not reset on ... Common Mistake #1: Accessing The Scope Through The...
Read more >
Compose UI | Jetpack
Updated DrawScope api to introduce the ability to retarget rendering into a different canvas with alternative density/layoutdirection and size.
Read more >
What is Regression Testing? Test Cases (Example)
Regression Testing means to confirm that a recent program or code change has not adversely affected existing features. In this tutorial ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found