-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Blur previous element when interacting with Cesium canvas. #8662
Conversation
Interacting with a canvas does not automatically blur the previously focused element. This leads to unexpected interaction if the last element was an input field. For example, clicking the mouse wheel could lead to the value in the field changing unexpectedly. The solution is to blur whatever has focus as soon as canvas interaction begins.
Thanks for the pull request @mramato!
Reviewers, don't forget to make sure that:
|
This seems like a good idea. One concern I might have is that there might not be a way to get the canvas to receive keyboard input, like hotkeys, if any apps are using that. Clicking the canvas will cause it to blur itself. Not sure the solution... maybe blur the active element and then attempt to focus the canvas? Or just double-check that it's not the canvas that's being blurred? |
Good thinking. However I'm having a hard time actually triggering what I agree would be a bug in the fix here. I'm using this demo to test: http://localhost:8080/Apps/Sandcastle/index.html?src=HeadingPitchRoll.html It listens to the document element, but with my code in this branch it still works. I assume this is because the event bubbles up to the document when no element has focus. This demo is also kind of sloppy by listening to document because if you active the geocoder and press up/down, it still affects the plane instead of the geocoder. Working on that assumption, I then changed the Sandcastle to use So it appears that nothing extra is actually needed here, but I don't fully understand what. Thoughts? |
Yeah that does seem to work. The demo's click handler is registered after the viewer is constructed (of course, because prior to that there's no canvas). So I guess the blur happens before the focus, and everything is OK. I still feel like it would be good to check that the canvas isn't blurring itself. But I don't quite know how an app would manage to get into that state exactly. |
So yeah, if the canvas doesn't |
In this demo, click-to-focus is commented out. One must instead click on the Cesium tab title, where it says the branch name above the Cesium window. The branch name should get a blue outline when you do this. Then, press TAB, and now the canvas has focus. Now you can use the arrow keys to fly the plane. But if you click the canvas, it blurs itself, losing focus. Clearly a mainstream use case here. |
Thanks for your diligence here @emackey, I pushed a fix to check if canvas is the element focused before blurring. |
Interacting with a canvas does not automatically blur the previously focused element. This leads to unexpected interaction if the last element was an input field. For example, clicking the mouse wheel could lead to the value in the field changing unexpectedly. The solution is to blur whatever has focus as soon as canvas interaction begins.
@emackey can you see any flaws/problems in this approach?