@@ -18,7 +18,6 @@ import {
1818 createContext ,
1919 type MouseEvent ,
2020 useContext ,
21- useEffect ,
2221 useRef ,
2322 useState ,
2423} from "react" ;
@@ -89,47 +88,11 @@ export const ActionsMenu: React.FC<ActionsMenuProps> = ({
8988 const click = useClick ( context ) ;
9089 const dismiss = useDismiss ( context ) ;
9190 const role = useRole ( context , { role : "menu" } ) ;
92- // Create a dense array for FloatingUI and mapping back to sparse array
93- const denseListRef = useRef < Array < HTMLElement > > ( [ ] ) ;
94- const sparseToCompactMap = useRef < Map < number , number > > ( new Map ( ) ) ;
95- const compactToSparseMap = useRef < Map < number , number > > ( new Map ( ) ) ;
96-
97- // Update dense list and mappings when listRef changes
98- useEffect ( ( ) => {
99- const denseArray : HTMLElement [ ] = [ ] ;
100- sparseToCompactMap . current . clear ( ) ;
101- compactToSparseMap . current . clear ( ) ;
102-
103- listRef . current . forEach ( ( item , sparseIndex ) => {
104- if ( item !== null ) {
105- const compactIndex = denseArray . length ;
106- denseArray . push ( item ) ;
107- sparseToCompactMap . current . set ( sparseIndex , compactIndex ) ;
108- compactToSparseMap . current . set ( compactIndex , sparseIndex ) ;
109- }
110- } ) ;
111-
112- denseListRef . current = denseArray ;
113- } ) ;
114-
115- // Convert sparse activeIndex to compact activeIndex for FloatingUI
116- const compactActiveIndex =
117- activeIndex !== null
118- ? ( sparseToCompactMap . current . get ( activeIndex ) ?? null )
119- : null ;
12091
12192 const listNavigation = useListNavigation ( context , {
122- listRef : denseListRef ,
123- activeIndex : compactActiveIndex ,
124- onNavigate : ( compactIndex ) => {
125- const sparseIndex =
126- compactIndex !== null && compactIndex !== undefined
127- ? ( compactToSparseMap . current . get ( compactIndex ) ?? null )
128- : null ;
129- if ( sparseIndex !== null ) {
130- setActiveIndex ( sparseIndex ) ;
131- }
132- } ,
93+ listRef,
94+ activeIndex,
95+ onNavigate : setActiveIndex ,
13396 focusItemOnHover : false ,
13497 loop : true ,
13598 } ) ;
0 commit comments