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

fix: SplitButton.Click is not fired when SplitButton is not in focused #16940

Conversation

workgroupengineering
Copy link
Contributor

What does the pull request do?

What is the current behavior?

What is the updated/expected behavior with this PR?

How was the solution implemented (if it's not obvious)?

Checklist

Breaking changes

Obsoletions / Deprecations

Fixed issues

Continue of #16184

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0051684-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

base.OnKeyDown(e);
}

/// <inheritdoc/>
protected override void OnKeyUp(KeyEventArgs e)
{
var key = e.Key;
Copy link
Contributor

Choose a reason for hiding this comment

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

For both of these changes it's a lot easier to read the changes if you just check and exit on entry:

if (!IsFocused)
{
    base.OnKeyUp(e);
    return;
}
  1. That would remove a lot of noise in this PR
  2. It helps with maintainability and readability to reduce nesting in the logic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I preferred this solution because IL is more compact, see example.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think IL really matters here, as JIT might produce very similarly efficient code in the end.
But I don't like doubling base.OnKeyUp(e); call. Early returns are great, but duplicating base calls is not so much.

var key = e.Key;

if (key == Key.Space || key == Key.Enter)
if (IsFocused)
Copy link
Contributor

Choose a reason for hiding this comment

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

What about IsEffectivelyEnabled? We should probably check that too, right?

@robloo
Copy link
Contributor

robloo commented Sep 5, 2024

@workgroupengineering Whatever is done here MUST also be done to button. SplitButton copied the logic from Button originally so it would have the same issue.

Edit: Looking back at the Button PR for similar issue's you are not implementing the changes the same. I don't think that's a good idea. Button itself probably shouldn't even process Enter if it isn't focused or enabled. I would exit at the beginning of OnKeyUp/Down in Button as well. (Unless I'm missing something).

Code should not diverge like this (admittedly this is my fault I'm going to have to fix in Avalonia 12. I shouldn't have followed WinUI and should just have inherited Button in SplitButton).

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0051696-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Copy link
Member

@MrJul MrJul left a comment

Choose a reason for hiding this comment

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

I agree with @robloo here: other keys should still be processed even if the SplitButton doesn't have the focus directly, as the focus is probably on a child.

We should special case Space only, matching Button.

(As I mentioned in the PR for Button, ideally we shouldn't have anything to do at all. These PR are workarounds for a very specific issue, as redesigning the whole input system isn't on the table right now.)

@robloo
Copy link
Contributor

robloo commented Sep 26, 2024

I had another thought here. This situation isn't even handled well in WinUI. Microsoft probably made a mistake adding Space key support for controls like Button. ENTER alone is just fine for usability.

We might want to completely remove space handling from Button and SplitButton honestly.

@maxkatz6
Copy link
Member

Space handling is a bit wider question, and also touches how we map controller keys (which is supported in 11.1 on backend-basis):
https://learn.microsoft.com/en-us/windows/apps/design/input/gamepad-and-remote-interactions#built-in-button-support

https://github.com/AvaloniaUI/Avalonia/blob/master/src/Android/Avalonia.Android/Platform/Input/AndroidKeyboardDevice.cs#L212

UIPressType.Select => PhysicalKey.Space,

[UIKeyboardHidUsage.KeyboardSelect] = PhysicalKey.Space,

(and the same is done in Tizen, but I think on Tizen SDK side automatically)

@MrJul
Copy link
Member

MrJul commented Oct 3, 2024

We might want to completely remove space handling from Button and SplitButton honestly.

I disagree, Space has been used to press buttons since at least Windows 3.1. Personally, I'm still using this very often, in a variety of programs. This shouldn't be removed from Avalonia because of this issue.

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.3.999-cibuild0052409-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Copy link
Member

@MrJul MrJul left a comment

Choose a reason for hiding this comment

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

The changes now match the ones for Button (#16619).
LGTM, thanks!

@MrJul MrJul enabled auto-merge October 7, 2024 11:07
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.3.999-cibuild0052431-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul added this pull request to the merge queue Oct 7, 2024
@MrJul MrJul added the backport-candidate-11.2.x Consider this PR for backporting to 11.2 branch label Oct 7, 2024
Merged via the queue into AvaloniaUI:master with commit b11574a Oct 7, 2024
10 of 11 checks passed
@workgroupengineering workgroupengineering deleted the fix/Controls/SplitButton/Issue_#16184 branch October 7, 2024 16:44
@MrJul MrJul added the bug label Oct 7, 2024
maxkatz6 pushed a commit that referenced this pull request Oct 27, 2024
…cused (#16940)

* test: Check that `SplitButton.Click` is not fired when `SplitButton` is not in focused

* fix: `SplitButton.Click` is not fired when `SplitButton` is not in focused

* fix: Address review

* fix: Address review

---------

Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
@maxkatz6 maxkatz6 added backported-11.2.x and removed backport-candidate-11.2.x Consider this PR for backporting to 11.2 branch labels Oct 27, 2024
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.

5 participants