mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-10-12 23:48:57 +00:00
21a6cb42fe
This PR fixes two issues that can cause a degraded user experience under certain conditions: ### Focus-stealing When focus lands on the `document.body`, it's typically bad for accessibility and a sign of improper input handling. This generally occurs when the currently-focused element is removed from the DOM. In our particular case, it also prevents the Bevy application from correctly handling keyboard events. Previously, the problem of `document.body` focus had been fixed by checking the `document.activeElement` every frame, and redirecting focus to the Bevy canvas whenever it landed on the `document.body`. However, when running in an iframe embedded on https://fakeyou.com, our application will report `document.body` as the `document.activeElement` whenever the parent application has focus, effectively stealing focus from the parent application and making it impossible for the user to, e.g., interact with text fields in the parent app. This PR removes that focus-stealing behavior. Instead, we should properly implement the ARIA specifications for any elements that may disappear from the DOM so that user focus is managed in a precise and predictable way. That will be addressed in follow-up PRs. ### "Stuck" input states In certain circumstances, the browser window hosting our application may lose focus while certain keys/buttons are held down which are bound to long-running actions in the Bevy application, like camera manipulation. When that occurs, Bevy is unable to detect when the bound keys/buttons are released, causing the input state to become "stuck" reading those keys/buttons as being pressed. As a workaround, this PR introduces a listener for "blur" events on the `window`, which dispatches synthetic "keyup"/"pointerup" events to the Bevy canvas for all affected keyboard keys and mouse buttons.