@@ -8,14 +8,33 @@ import { useUniqueId } from '../hooks/useUniqueId';
88import { NodeOrientation } from '../types/orientation' ;
99import { NodeIndexRange } from '@bam.tech/lrud' ;
1010import { SpatialNavigationNodeRef } from '../types/SpatialNavigationNodeRef' ;
11+ import { useIsRootActive } from '../context/IsRootActiveContext' ;
1112
1213type FocusableProps = {
1314 isFocusable : true ;
14- children : ( props : { isFocused : boolean ; isActive : boolean } ) => React . ReactElement ;
15+ children : ( props : {
16+ /** Returns whether the root is focused or not. */
17+ isFocused : boolean ;
18+ /** Returns whether the root is active or not. An active node is active if one of its children is focused. */
19+ isActive : boolean ;
20+ /** Returns whether the root is active or not.
21+ * This is very handy if you want to hide the focus on your page elements when
22+ * the side-menu is focused (since it is a different root navigator) */
23+ isRootActive : boolean ;
24+ } ) => React . ReactElement ;
1525} ;
1626type NonFocusableProps = {
1727 isFocusable ?: false ;
18- children : React . ReactElement | ( ( props : { isActive : boolean } ) => React . ReactElement ) ;
28+ children :
29+ | React . ReactElement
30+ | ( ( props : {
31+ /** Returns whether the root is active or not. An active node is active if one of its children is focused. */
32+ isActive : boolean ;
33+ /** Returns whether the root is active or not.
34+ * This is very handy if you want to hide the focus on your page elements when
35+ * the side-menu is focused (since it is a different root navigator) */
36+ isRootActive : boolean ;
37+ } ) => React . ReactElement ) ;
1938} ;
2039type DefaultProps = {
2140 onFocus ?: ( ) => void ;
@@ -95,6 +114,7 @@ export const SpatialNavigationNode = forwardRef<SpatialNavigationNodeRef, Props>
95114 ) => {
96115 const spatialNavigator = useSpatialNavigator ( ) ;
97116 const parentId = useParentId ( ) ;
117+ const isRootActive = useIsRootActive ( ) ;
98118 const [ isFocused , setIsFocused ] = useState ( false ) ;
99119 const [ isActive , setIsActive ] = useState ( false ) ;
100120 // If parent changes, we have to re-register the Node + all children -> adding the parentId to the nodeId makes the children re-register.
@@ -180,7 +200,7 @@ export const SpatialNavigationNode = forwardRef<SpatialNavigationNodeRef, Props>
180200 return (
181201 < ParentIdContext . Provider value = { id } >
182202 { typeof children === 'function'
183- ? bindRefToChild ( children ( { isFocused, isActive } ) )
203+ ? bindRefToChild ( children ( { isFocused, isActive, isRootActive } ) )
184204 : children }
185205 </ ParentIdContext . Provider >
186206 ) ;
0 commit comments