Skip to content

Create focus.md #392

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

Merged
merged 3 commits into from
Mar 13, 2024
Merged

Create focus.md #392

merged 3 commits into from
Mar 13, 2024

Conversation

stevemonaco
Copy link
Collaborator

Creates general documentation for all focus-related features I'm aware of, including XYFocus.

I wasn't able to think of a compelling example of tab navigation and most other features are "basic", so I only added an example for XYFocus. If more are added, Focus may need to be split into several documents.

Tab focus navigation may be a bit suspect/underdeveloped as I don't understand the area well. Particularly this statement is hand-wavy:

When `TabIndex` is equal, the order of appearance within the Visual Tree is used.

Part of: #384


Focus navigation by tab occurs when the user presses tab on their keyboard. `InputElement`s with their `IsTabStop` property
set to `true` will be available for tab focus navigation. The `TabIndex` specifies the priority with lower numeric values being
navigated to first. When `TabIndex` is equal, the order of appearance within the Visual Tree is used.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, something like "When TabIndex is equal, the order in which control is definition used". It's not entirely true, but should be good enough simplification.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels a bit too simple because that only makes sense in the context of a single XAML document, not necessarily across documents or anything created by code.

|:---------------|--------------------------------------------------------------------------------|
| :focus | The Control has focus. |
| :focus-within | The Control has focus or contains a descendant that has focus. |
| :focus-visible | The Control has focus and received it from Tab or Directional focus navigation |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be more specific, focus-visible tells that control should use focus styles. Like, text box changes its appearance when focused. Additionally, if control overrides :focus-visible, it might need to set FocusAdorner to null:
https://github.com/AvaloniaUI/Avalonia/blob/0cd220f6c2ae409f5a27c261d09c2eb5836ad2fe/src/Avalonia.Themes.Fluent/Controls/TextBox.xaml#L107

As otherwise double focus visuals would be applied.

## Directional Focus Navigation <MinVersion version="11.1" />

Focus navigation through `XYFocus` is a 2D directional scheme enabling spatial navigation from the focused control
towards another control to a cardinal direction: left, right, up, or down. `XYFocus.NavigationModes` is `Disabled` by
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, it's Gamepad | Remote. Which means, it is enabled only for these types of controllers.

Comment on lines 89 to 90
`KeyDeviceType.Gamepad` is not yet supported, so `XYFocus` navigation is currently limited to `Keyboard` (arrow keys)
and `Remote` (tvOS most commonly).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gamepad is technically supported, as Android and Tizen already can send this kind of input. We don't have a proper Gamepad APIs, but that's a different story, not related to XY focus or KeyDeviceType.

Comment on lines 123 to 128
<Style Selector=":is(Control).directional-navigation">
<Setter Property="XYFocus.NavigationModes" Value="Enabled" />
<Setter Property="XYFocus.UpNavigationStrategy" Value="Projection" />
<Setter Property="XYFocus.DownNavigationStrategy" Value="Projection" />
<Setter Property="XYFocus.LeftNavigationStrategy" Value="Projection" />
<Setter Property="XYFocus.RightNavigationStrategy" Value="Projection" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These properties are inheritable, so it might make more sense to set it on top level.

@stevemonaco
Copy link
Collaborator Author

stevemonaco commented Mar 13, 2024

Thanks for the review. Fixed the errors, added suggestions, and cleaned up some new nits after another proofread pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants