Skip to content

FocusManager and KeyboardDevice should stay in sync #21013

@MrJul

Description

@MrJul

Describe the bug

FocusManager.Focus() ultimately calls KeyboardDevice.SetFocusedElement.

However, since #18373, a focus change can be cancelled. If it is, that information is not propagated back to the FocusManager, which incorrectly sets the wrong FocusedElement to the current focus scope.

To Reproduce

  1. Call FocusManager.Focus
  2. Handle FocusChanging and call TryCancel on the event arguments.
  3. Notice that FocusManager.FocusedElement on the current scope has still be changed.

Expected behavior

When FocusManager.Focus() internally calls KeyboardDevice.SetFocusedElement(), it should verify that the focused element effectively changed. If it didn't or was redirected, the focused element should be updated to the current element, and Focus() should return false.

Avalonia version

12.0.0-rc2, master

OS

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions