-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Merged
MrJul
merged 5 commits into
AvaloniaUI:master
from
workgroupengineering:fix/Controls/SplitButton/Issue_#16184
Oct 7, 2024
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a691864
test: Check that `SplitButton.Click` is not fired when `SplitButton` …
workgroupengineering 4ceabae
fix: `SplitButton.Click` is not fired when `SplitButton` is not in fo…
workgroupengineering 1050d79
fix: Address review
workgroupengineering 20a5d59
fix: Address review
workgroupengineering 58c75b9
Merge branch 'master' into fix/Controls/SplitButton/Issue_#16184
MrJul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -345,52 +345,55 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs e) | |
protected override void OnKeyDown(KeyEventArgs e) | ||
{ | ||
var key = e.Key; | ||
|
||
if (key == Key.Space || key == Key.Enter) | ||
if (IsFocused) | ||
{ | ||
_isKeyboardPressed = true; | ||
UpdatePseudoClasses(); | ||
if (key == Key.Space || key == Key.Enter) | ||
{ | ||
_isKeyboardPressed = true; | ||
UpdatePseudoClasses(); | ||
} | ||
} | ||
|
||
base.OnKeyDown(e); | ||
} | ||
|
||
/// <inheritdoc/> | ||
protected override void OnKeyUp(KeyEventArgs e) | ||
{ | ||
var key = e.Key; | ||
|
||
if (key == Key.Space || key == Key.Enter) | ||
if (IsFocused) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about IsEffectivelyEnabled? We should probably check that too, right? |
||
{ | ||
_isKeyboardPressed = false; | ||
UpdatePseudoClasses(); | ||
var key = e.Key; | ||
|
||
// Consider this a click on the primary button | ||
if (IsEffectivelyEnabled) | ||
if (key == Key.Space || key == Key.Enter) | ||
{ | ||
OnClickPrimary(null); | ||
_isKeyboardPressed = false; | ||
UpdatePseudoClasses(); | ||
|
||
// Consider this a click on the primary button | ||
if (IsEffectivelyEnabled) | ||
{ | ||
OnClickPrimary(null); | ||
e.Handled = true; | ||
} | ||
} | ||
else if (key == Key.Down && e.KeyModifiers.HasAllFlags(KeyModifiers.Alt) && IsEffectivelyEnabled | ||
&& !XYFocusHelpers.IsAllowedXYNavigationMode(this, e.KeyDeviceType)) | ||
{ | ||
OpenFlyout(); | ||
e.Handled = true; | ||
} | ||
else if (key == Key.F4 && IsEffectivelyEnabled) | ||
{ | ||
OpenFlyout(); | ||
e.Handled = true; | ||
} | ||
else if (e.Key == Key.Escape && _isFlyoutOpen) | ||
{ | ||
// If Flyout doesn't have focusable content, close the flyout here | ||
// This is the same behavior as Button | ||
CloseFlyout(); | ||
e.Handled = true; | ||
} | ||
} | ||
else if (key == Key.Down && e.KeyModifiers.HasAllFlags(KeyModifiers.Alt) && IsEffectivelyEnabled | ||
&& !XYFocusHelpers.IsAllowedXYNavigationMode(this, e.KeyDeviceType)) | ||
{ | ||
OpenFlyout(); | ||
e.Handled = true; | ||
} | ||
else if (key == Key.F4 && IsEffectivelyEnabled) | ||
{ | ||
OpenFlyout(); | ||
e.Handled = true; | ||
} | ||
else if (e.Key == Key.Escape && _isFlyoutOpen) | ||
{ | ||
// If Flyout doesn't have focusable content, close the flyout here | ||
// This is the same behavior as Button | ||
CloseFlyout(); | ||
e.Handled = true; | ||
} | ||
|
||
base.OnKeyUp(e); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.