-
Notifications
You must be signed in to change notification settings - Fork 85
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
Make clickable react to NumPadEnter and Spacebar, too #1464
Make clickable react to NumPadEnter and Spacebar, too #1464
Conversation
Adding a bunch of tests, too, to ensure clickable responds to Enter (existing behaviour, not tested), NumPadEnter, and Spacebar. Testing that toggleable and selectable have the same behaviour, since they both use clickable under the hood.
compose/foundation/foundation/src/skikoTest/kotlin/androidx/compose/foundation/ClickableTest.kt
Outdated
Show resolved
Hide resolved
First thing that comes to mind is an onPreviewKeyEvent that returns true when the key is a space at, placed after clickable |
But this return unknown code key in window key event. |
Not sure what that means |
我真的不知道你们脑袋里面在想什么,作为桌面端程序,按空格键预览图片不是很常见的操作吗?你这样搞了之后,我这边事件全部错乱了呀,能不能好好的改bug,别加这些莫名其妙的特性?这样真的很烦! |
@michaellee123 |
This change made spacebar completely unusable as a global hotkey for the whole window (I've used it as a "pause" in my app). Also global hotkeys already were a pain because of https://youtrack.jetbrains.com/issue/CMP-1925, but at least it worked with the help of I use the following code now:
So now i must choose between:
Maybe you can give me any advice? |
@badmannersteam the issue you're seeing seems more due to CMP-1925 than this change, tbh It's correct for spacebar and numpadenter to trigger click on the focused component — that is what all UI frameworks do. The bug is probably separate here — is clickable using an onPreviewKeyEvent handler that intercepts the keypress before others do? That would be wrong. I'd suggest opening a bug on YouTrack though, because a merged PR is not really a good place to file issues... PS: you could consider finding the root cause of the issue and opening a PR to fix it if it's urgent for you — that is what I did here. |
I agree with Enters, but not with Space - nor system Windows apps like Explorer, nor crosplatform apps like Chrome perform click with Space, only with Enters.
Yes, will do this, just asking before - maybe there is an obvious solution that I didn't find.
I'm afraid that my understanding of current implementation of keyboard handlers is not enough. Thanks for your answer. |
I checked Windows 11 native apps, and they perform the action on Space for most clickable components when they are in focus:
If you need customization of clicks/key handling, you should use |
The
Clickable
modifier only reacts to the "main" Enter key. This PR makes it also respond to the numpad Enter key, and the spacebar key.Fixes CMP-5732
Testing
Smoke tested on the desktop demo: clickable composables react as expected.
Added a lot of tests to ensure the behavior is correct for previous and new keys (there were no tests).
QA should probably test this.
Release Notes
Features - Multiple platforms
clickable
modifier now responds to NumPadEnter and Spacebar, too, in addition to Enter.