File tree Expand file tree Collapse file tree
packages/components/src/content-nav Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,6 +25,10 @@ export function useActiveSync(options: ContentNavActiveSyncOptions) {
2525 const preferredReducedMotion = usePreferredReducedMotion ( )
2626
2727 function setActiveId ( value : string | undefined ) {
28+ if ( activeId . value === value ) {
29+ return
30+ }
31+
2832 if ( options . activeId ?. value === undefined ) {
2933 localActiveId . value = value
3034 }
@@ -137,7 +141,6 @@ export function useActiveSync(options: ContentNavActiveSyncOptions) {
137141 scrollHeight : getContentNavScrollHeight ( scrollRoot ) ,
138142 } ,
139143 anchors,
140- items : options . items . value ,
141144 activeOffset : options . activeOffset ?. value ,
142145 } )
143146
Original file line number Diff line number Diff line change @@ -34,22 +34,22 @@ export function defaultContentNavActiveResolver(options: {
3434 scrollHeight : number
3535 }
3636 anchors : Array < { id : string ; el : HTMLElement } >
37- items : ContentNavItem [ ]
3837 activeOffset ?: number
3938} ) {
40- const { viewport, anchors, items } = options
39+ const { viewport, anchors } = options
4140
42- if ( ! anchors . length || ! items . length ) {
43- return items [ 0 ] ?. id
41+ if ( ! anchors . length ) {
42+ return
4443 }
4544
45+ const canScroll = viewport . scrollHeight - viewport . clientHeight > 2
4646 const isAtBottom = viewport . scrollTop + viewport . clientHeight >= viewport . scrollHeight - 2
47- if ( isAtBottom ) {
48- return items [ items . length - 1 ] ?. id
47+ if ( canScroll && isAtBottom ) {
48+ return anchors [ anchors . length - 1 ] ?. id
4949 }
5050
5151 const threshold = viewport . top + Math . max ( 0 , options . activeOffset ?? 120 )
52- let activeId = items [ 0 ] ?. id
52+ let activeId = anchors [ 0 ] ?. id
5353
5454 for ( const anchor of anchors ) {
5555 const rect = anchor . el . getBoundingClientRect ( )
You can’t perform that action at this time.
0 commit comments