@@ -119,6 +119,9 @@ export function useMenuItem<T>(props: AriaMenuItemProps, state: TreeState<T>, re
119
119
120
120
let onSubmenuOpen = useEffectEvent ( ( ) => {
121
121
cancelOpenTimeout ( ) ;
122
+ for ( let expandedKey of state . expandedKeys ) {
123
+ state . toggleKey ( expandedKey ) ;
124
+ }
122
125
if ( ! state . expandedKeys . has ( key ) ) {
123
126
state . toggleKey ( key ) ;
124
127
}
@@ -198,27 +201,22 @@ export function useMenuItem<T>(props: AriaMenuItemProps, state: TreeState<T>, re
198
201
allowsDifferentPressOrigin : true
199
202
} ) ;
200
203
201
- let { pressProps, isPressed} = usePress ( { onPressStart, onPressUp, isDisabled} ) ;
204
+ let { pressProps, isPressed} = usePress ( { onPressStart, onPressUp, isDisabled : isDisabled || ( isMenuDialogTrigger && state . expandedKeys . has ( key ) ) } ) ;
202
205
let { hoverProps} = useHover ( {
203
206
isDisabled,
204
207
onHoverStart ( ) {
205
- if ( ! isFocusVisible ( ) ) {
208
+ if ( ! isFocusVisible ( ) && ! ( isMenuDialogTrigger && state . expandedKeys . has ( key ) ) ) {
206
209
state . selectionManager . setFocused ( true ) ;
207
210
state . selectionManager . setFocusedKey ( key ) ;
208
211
// focus immediately so that a focus scope opened on hover has the correct restore node
209
212
let isFocused = key === state . selectionManager . focusedKey ;
210
213
if ( isFocused && state . selectionManager . isFocused && document . activeElement !== ref . current ) {
211
- if ( state . expandedKeys . size > 0 && ! state . expandedKeys . has ( key ) ) {
212
- for ( let expandedKey of state . expandedKeys ) {
213
- state . toggleKey ( expandedKey ) ;
214
- }
215
- }
216
214
focusSafely ( ref . current ) ;
217
215
}
218
216
}
219
217
} ,
220
218
onHoverChange : isHovered => {
221
- if ( isHovered && isMenuDialogTrigger ) {
219
+ if ( isHovered && isMenuDialogTrigger && ! state . expandedKeys . has ( key ) ) {
222
220
if ( ! openTimeout . current ) {
223
221
openTimeout . current = setTimeout ( ( ) => {
224
222
onSubmenuOpen ( ) ;
0 commit comments