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

SettingsExpander is swallowing space key #591

Open
thexamlguy opened this issue Jun 26, 2024 · 2 comments
Open

SettingsExpander is swallowing space key #591

thexamlguy opened this issue Jun 26, 2024 · 2 comments
Labels
Bug in Avalonia Issue is a bug in Avalonia and has no fix in FA bug Something isn't working

Comments

@thexamlguy
Copy link

thexamlguy commented Jun 26, 2024

Describe the bug
When using a TextBox as the SettingsExpander's Footer content, spaces cannot be entered into the TextBox. Typing characters works normally, but pressing the spacebar has no effect.

To Reproduce
Steps to reproduce the behavior:

  1. Create a SettingsExpander component.
  2. Set a TextBox as the SettingsExpander.Footer content.
  3. Run the application.
  4. Try to type into the TextBox and attempt to enter spaces.

Code Example

          <ui:SettingsExpander>
              <ui:SettingsExpander.Footer>
                  <TextBox Width="300" />
              </ui:SettingsExpander.Footer>
          </ui:SettingsExpander>

Expected behavior
Spaces should be entered into the TextBox when the spacebar is pressed.

Actual behavior
Characters can be entered into the TextBox, but spaces cannot.

Desktop/Platform

OS: Windows 11
FluentAvalonia Version: 2.1.0-preview6
Avalonia Version: 11.1.0-rc1

@thexamlguy thexamlguy added the bug Something isn't working label Jun 26, 2024
@thexamlguy
Copy link
Author

This appears to be the toggle button that is handling the Space key. For now I've worked around this issue by adding a custom ToggleButton and re-templated the SettingsExpander style to replace the ToggleButton with the custom ToggleButton.

public class SettingsExpanderToggleButton : ToggleButton
{
    protected override void OnKeyDown(KeyEventArgs args)
    {
        if (args.Key == Key.Space)
        {
            IsChecked = !IsChecked;
        }
        else
        {
            base.OnKeyDown(args);
        }
    }
}

@amwx
Copy link
Owner

amwx commented Jul 1, 2024

So this is a bug in Avalonia because Button is handling all key down events as part of its core logic. For most cases this is fine (you normally don't put a textbox in a button. But for Expander, the entire header is a button and we hit this problem.
I opened an issue upstream with a solution that WPF uses.

@amwx amwx added the Bug in Avalonia Issue is a bug in Avalonia and has no fix in FA label Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug in Avalonia Issue is a bug in Avalonia and has no fix in FA bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants