File tree Expand file tree Collapse file tree 3 files changed +16
-1
lines changed
@headlessui-react/src/components Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -537,7 +537,7 @@ function Option<
537537 let d = disposables ( )
538538 d . nextFrame ( ( ) => document . getElementById ( id ) ?. scrollIntoView ?.( { block : 'nearest' } ) )
539539 return d . dispose
540- } , [ active , state . listboxState ] )
540+ } , [ id , active , state . listboxState ] )
541541
542542 let handleClick = useCallback (
543543 ( event : { preventDefault : Function } ) => {
Original file line number Diff line number Diff line change @@ -423,6 +423,14 @@ function Item<TTag extends ElementType = typeof DEFAULT_ITEM_TAG>(
423423 let id = `headlessui-menu-item-${ useId ( ) } `
424424 let active = state . activeItemIndex !== null ? state . items [ state . activeItemIndex ] . id === id : false
425425
426+ useIsoMorphicEffect ( ( ) => {
427+ if ( state . menuState !== MenuStates . Open ) return
428+ if ( ! active ) return
429+ let d = disposables ( )
430+ d . nextFrame ( ( ) => document . getElementById ( id ) ?. scrollIntoView ?.( { block : 'nearest' } ) )
431+ return d . dispose
432+ } , [ id , active , state . menuState ] )
433+
426434 let bag = useRef < MenuItemDataRef [ 'current' ] > ( { disabled } )
427435
428436 useIsoMorphicEffect ( ( ) => {
Original file line number Diff line number Diff line change 99 nextTick ,
1010 InjectionKey ,
1111 Ref ,
12+ watchEffect ,
1213} from 'vue'
1314import { Features , render } from '../../utils/render'
1415import { useId } from '../../hooks/use-id'
@@ -370,6 +371,12 @@ export let MenuItem = defineComponent({
370371 onMounted ( ( ) => api . registerItem ( id , dataRef ) )
371372 onUnmounted ( ( ) => api . unregisterItem ( id ) )
372373
374+ watchEffect ( ( ) => {
375+ if ( api . menuState . value !== MenuStates . Open ) return
376+ if ( ! active . value ) return
377+ nextTick ( ( ) => document . getElementById ( id ) ?. scrollIntoView ?.( { block : 'nearest' } ) )
378+ } )
379+
373380 function handleClick ( event : MouseEvent ) {
374381 if ( disabled ) return event . preventDefault ( )
375382 api . closeMenu ( )
You can’t perform that action at this time.
0 commit comments