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<
537
537
let d = disposables ( )
538
538
d . nextFrame ( ( ) => document . getElementById ( id ) ?. scrollIntoView ?.( { block : 'nearest' } ) )
539
539
return d . dispose
540
- } , [ active , state . listboxState ] )
540
+ } , [ id , active , state . listboxState ] )
541
541
542
542
let handleClick = useCallback (
543
543
( 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>(
423
423
let id = `headlessui-menu-item-${ useId ( ) } `
424
424
let active = state . activeItemIndex !== null ? state . items [ state . activeItemIndex ] . id === id : false
425
425
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
+
426
434
let bag = useRef < MenuItemDataRef [ 'current' ] > ( { disabled } )
427
435
428
436
useIsoMorphicEffect ( ( ) => {
Original file line number Diff line number Diff line change 9
9
nextTick ,
10
10
InjectionKey ,
11
11
Ref ,
12
+ watchEffect ,
12
13
} from 'vue'
13
14
import { Features , render } from '../../utils/render'
14
15
import { useId } from '../../hooks/use-id'
@@ -370,6 +371,12 @@ export let MenuItem = defineComponent({
370
371
onMounted ( ( ) => api . registerItem ( id , dataRef ) )
371
372
onUnmounted ( ( ) => api . unregisterItem ( id ) )
372
373
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
+
373
380
function handleClick ( event : MouseEvent ) {
374
381
if ( disabled ) return event . preventDefault ( )
375
382
api . closeMenu ( )
You can’t perform that action at this time.
0 commit comments