@@ -835,12 +835,14 @@ class SpatialNavigationService {
835835 this . onEnterRelease ( ) ;
836836 }
837837
838- if ( this . focusKey && (
839- eventType === DIRECTION_LEFT ||
840- eventType === DIRECTION_RIGHT ||
841- eventType === DIRECTION_UP ||
842- eventType === DIRECTION_DOWN ) ) {
843- this . onArrowRelease ( eventType )
838+ if (
839+ this . focusKey &&
840+ ( eventType === DIRECTION_LEFT ||
841+ eventType === DIRECTION_RIGHT ||
842+ eventType === DIRECTION_UP ||
843+ eventType === DIRECTION_DOWN )
844+ ) {
845+ this . onArrowRelease ( eventType ) ;
844846 }
845847 } ;
846848
@@ -1025,7 +1027,18 @@ class SpatialNavigationService {
10251027 * the Focusable Containers, that have "forceFocus" flag enabled.
10261028 */
10271029 if ( ! fromParentFocusKey && ! currentComponent ) {
1028- this . setFocus ( this . getForcedFocusKey ( ) ) ;
1030+ const forcedKey = this . getForcedFocusKey ( ) ;
1031+
1032+ if ( forcedKey ) {
1033+ this . setFocus ( forcedKey ) ;
1034+ } else {
1035+ this . log (
1036+ 'smartNavigate' ,
1037+ 'Aborted due to missing current component and force-focusable key'
1038+ ) ;
1039+ }
1040+
1041+ // Current component is null (e.g. nothing to navigate from)
10291042 return ;
10301043 }
10311044
@@ -1663,10 +1676,21 @@ class SpatialNavigationService {
16631676 if ( ! focusKey || focusKey === ROOT_FOCUS_KEY ) {
16641677 // eslint-disable-next-line no-param-reassign
16651678 focusKey = this . getForcedFocusKey ( ) ;
1679+
1680+ // If there is no force-focusable key either then we abort
1681+ if ( ! focusKey ) {
1682+ this . log ( 'setFocus' , 'Aborted due to missing force-focusable key' ) ;
1683+ return ;
1684+ }
16661685 }
16671686
16681687 const newFocusKey = this . getNextFocusKey ( focusKey ) ;
16691688
1689+ if ( ! newFocusKey ) {
1690+ this . log ( 'setFocus' , 'Aborted due to missing next focus key' ) ;
1691+ return ;
1692+ }
1693+
16701694 this . log ( 'setFocus' , 'newFocusKey' , newFocusKey ) ;
16711695
16721696 this . setCurrentFocusedKey ( newFocusKey , focusDetails ) ;
0 commit comments