This is a guard relevant to the use-case of UI fading out (specifically, when your last-focused component becomes unmounted upon fade-out, which leads to this.focusableComponents[this.focusKey] becoming undefined).
I prevent onEnterPress and onArrowPress from triggering if the focusKey no longer corresponds to a component. Otherwise, the app tries to access fields on the component variable, which evaluates to undefined, and thus results in a TypeError.
"Ideal behaviour" might arguably be to move focus to the next-closest focusable upon the user's current focus target unmounting (this would constitute a separate PR), but in my case, there were no enabled focusables anywhere in the app to move the target to, so we'd still need this guard either way.
This is a guard relevant to the use-case of UI fading out (specifically, when your last-focused component becomes unmounted upon fade-out, which leads to
this.focusableComponents[this.focusKey]
becomingundefined
).I prevent
onEnterPress
andonArrowPress
from triggering if the focusKey no longer corresponds to a component. Otherwise, the app tries to access fields on thecomponent
variable, which evaluates toundefined
, and thus results in a TypeError."Ideal behaviour" might arguably be to move focus to the next-closest focusable upon the user's current focus target unmounting (this would constitute a separate PR), but in my case, there were no enabled focusables anywhere in the app to move the target to, so we'd still need this guard either way.