@@ -18,7 +18,8 @@ import type {
1818import { Checkbox , CheckboxProps } from '@fluentui/react-checkbox' ;
1919import { Radio , RadioProps } from '@fluentui/react-radio' ;
2020import { TreeItemChevron } from '../TreeItemChevron' ;
21- import { useArrowNavigationGroup } from '@fluentui/react-tabster' ;
21+ import { useArrowNavigationGroup , useIsNavigatingWithKeyboard } from '@fluentui/react-tabster' ;
22+ import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts' ;
2223
2324/**
2425 * Create the state required to render TreeItemLayout.
@@ -88,6 +89,9 @@ export const useTreeItemLayout_unstable = (
8889 [ subtreeRef , setIsActionsVisible , onActionVisibilityChange ] ,
8990 ) ;
9091
92+ const { targetDocument } = useFluent ( ) ;
93+ const isNavigatingWithKeyboard = useIsNavigatingWithKeyboard ( ) ;
94+
9195 const setActionsInvisibleIfNotFromSubtree = React . useCallback (
9296 ( event : FocusEvent | MouseEvent ) => {
9397 const isRelatedTargetFromActions = ( ) =>
@@ -110,6 +114,17 @@ export const useTreeItemLayout_unstable = (
110114 if ( isTargetFromActions ( ) && isRelatedTargetFromTreeItem ( ) ) {
111115 return ;
112116 }
117+ // when a mouseout event happens during keyboard interaction
118+ // we should not hide the actions if the activeElement is the treeitem or an action
119+ // as the focus on the treeitem takes precedence over the mouseout event
120+ if (
121+ event . type === 'mouseout' &&
122+ isNavigatingWithKeyboard ( ) &&
123+ ( targetDocument ?. activeElement === treeItemRef . current ||
124+ elementContains ( actionsRefInternal . current , targetDocument ?. activeElement as Node ) )
125+ ) {
126+ return ;
127+ }
113128 onActionVisibilityChange ?.( event , {
114129 visible : false ,
115130 event,
@@ -120,7 +135,7 @@ export const useTreeItemLayout_unstable = (
120135 }
121136 setIsActionsVisible ( false ) ;
122137 } ,
123- [ setIsActionsVisible , onActionVisibilityChange , treeItemRef ] ,
138+ [ setIsActionsVisible , onActionVisibilityChange , treeItemRef , isNavigatingWithKeyboard , targetDocument ] ,
124139 ) ;
125140
126141 const expandIcon = slot . optional ( props . expandIcon , {
0 commit comments