Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing the focused element from the visual tree will not move focus to the "next focusable element", but to the first focusable element from root. #15942

Open
ramezgerges opened this issue Mar 19, 2024 · 1 comment
Assignees
Labels
area/focus Categorizes an issue as relevant to focus management difficulty/starter 🚀 Categorizes an issue for which the difficulty level is reachable by newcomers kind/bug Something isn't working platform/all Categorizes an issue or PR as relevant to the all platforms

Comments

@ramezgerges
Copy link
Contributor

Current behavior

This is because the element is removed from the tree before the element is Unloaded. On unloading, we call SetFocusOnNextFocusableElement, which calls GetNextTabStop. GetNextTabStop won't find any tab stops because the element is already removed from the visual tree. We will then fallback to the first focusable element in the tree, which is incorrect.
image

Expected behavior

No response

How to reproduce it (as minimally and precisely as possible)

<StackPanel x:Name="sp1">
  <StackPanel x:Name="sp2">
    <StackPanel x:Name="sp3">
      <Button x:Name="btn1"></Button>
      <Button x:Name="btn2"></Button>
    </StackPanel>
    <Button x:Name="btn3"></Button>
  </StackPanel>
</StackPanel>

Focus btn1 then remove it from the tree (I did this with a KeyDown callback on btn1). You should see the next focusable element (btn2) focused, but in Uno, this will cause the first focusable element from root to be focused.

Interestingly, in this repro, WinUI does something weird. It actually focuses btn3 instead of btn2.

Workaround

No response

Works on UWP/WinUI

None

Environment

No response

NuGet package version(s)

No response

Affected platforms

No response

IDE

No response

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

No response

@ramezgerges ramezgerges added kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. labels Mar 19, 2024
@Youssef1313
Copy link
Member

SetFocusOnNextFocusableElement should NOT be called in Unloaded. It should be called on Leave which we don't yet have, but we'll have when #14936 is merged

@MartinZikmund MartinZikmund self-assigned this Mar 20, 2024
@MartinZikmund MartinZikmund added area/skia ✏️ Categorizes an issue or PR as relevant to Skia platform/all Categorizes an issue or PR as relevant to the all platforms difficulty/starter 🚀 Categorizes an issue for which the difficulty level is reachable by newcomers area/focus Categorizes an issue as relevant to focus management and removed triage/untriaged Indicates an issue requires triaging or verification difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. area/skia ✏️ Categorizes an issue or PR as relevant to Skia labels Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/focus Categorizes an issue as relevant to focus management difficulty/starter 🚀 Categorizes an issue for which the difficulty level is reachable by newcomers kind/bug Something isn't working platform/all Categorizes an issue or PR as relevant to the all platforms
Projects
None yet
Development

No branches or pull requests

3 participants