@@ -17,7 +17,12 @@ class ScrollNavigationBar extends StreamlitComponentBase<State> {
1717 public state = { activeAnchorId : "" } ;
1818
1919 // Send message to COI
20- postMessage ( COI_method : string , data ?: { anchor_id ?: string ; anchor_ids ?: string [ ] } ) {
20+ postMessage ( COI_method : string ,
21+ data ?: {
22+ anchor_id ?: string ;
23+ anchor_ids ?:string [ ] ;
24+ auto_update_anchor ?: boolean
25+ } ) : void {
2126 const { key } = this . props . args ;
2227 if ( key == null || typeof key !== "string" ) {
2328 throw new Error ( "Invalid key: key must be a string." ) ;
@@ -27,21 +32,23 @@ class ScrollNavigationBar extends StreamlitComponentBase<State> {
2732 window . parent . postMessage ( { COI_method, key, anchor_id, anchor_ids } , "*" ) ;
2833 }
2934
35+ postRegister ( auto_update_anchor :boolean ) : void {
36+ this . postMessage ( "register" , { auto_update_anchor } ) ;
37+ console . debug ( "postRegister" ) ;
38+ }
3039 postScroll ( anchor_id : string ) : void {
3140 this . postMessage ( "scroll" , { anchor_id } ) ;
3241 console . debug ( "postScroll" , anchor_id ) ;
3342 }
34- postRegister ( ) : void {
35- this . postMessage ( "register" ) ;
36- console . debug ( "postRegister" ) ;
37- }
3843 postTrackAnchors ( anchor_ids : string [ ] ) : void {
3944 this . postMessage ( "trackAnchors" , { anchor_ids } ) ;
4045 console . debug ( "postTrackAnchors" , anchor_ids ) ;
4146 }
4247 postUpdateActiveAnchor ( anchor_id : string ) : void {
43- this . postMessage ( "updateActiveAnchor" , { anchor_id } ) ;
44- console . debug ( "postUpdateActiveAnchor" , anchor_id ) ;
48+ const { auto_update_anchor } = this . getCleanedArgs ( ) ;
49+ if ( auto_update_anchor )
50+ this . postMessage ( "updateActiveAnchor" , { anchor_id } ) ;
51+ console . debug ( "postUpdateActiveAnchor" , anchor_id , "; autoupdate" , auto_update_anchor ) ;
4552 }
4653
4754 // Handle menu item click
@@ -58,11 +65,11 @@ class ScrollNavigationBar extends StreamlitComponentBase<State> {
5865 } ;
5966
6067 public componentDidMount ( ) : void {
61- const { anchor_ids } = this . getCleanedArgs ( ) ;
68+ const { anchor_ids, auto_update_anchor } = this . getCleanedArgs ( ) ;
6269 const initialAnchorId = anchor_ids [ 0 ] ;
6370
6471 // Register component
65- this . postRegister ( ) ;
72+ this . postRegister ( auto_update_anchor ) ;
6673 // Tell COI to track anchors for visibility
6774 this . postTrackAnchors ( anchor_ids ) ;
6875 // Set initial active anchor for component and COI
@@ -114,7 +121,7 @@ class ScrollNavigationBar extends StreamlitComponentBase<State> {
114121 }
115122
116123 private getCleanedArgs ( ) {
117- let { key, anchor_ids, anchor_labels, anchor_icons, force_anchor, orientation, override_styles } = this . props . args ;
124+ let { key, anchor_ids, anchor_labels, anchor_icons, force_anchor, orientation, override_styles, auto_update_anchor } = this . props . args ;
118125 //key is required
119126 if ( key == null || typeof key !== "string" ) {
120127 throw new Error ( "Invalid key: key must be a string." ) ;
@@ -175,7 +182,18 @@ class ScrollNavigationBar extends StreamlitComponentBase<State> {
175182 }
176183 }
177184
178- return { anchor_ids, anchor_labels, anchor_icons, force_anchor, key, orientation, override_styles } ;
185+ //auto_update_active is an optional boolean
186+ //If not provided, default to true
187+ //If provided, it must be a boolean
188+ if ( auto_update_anchor == null ) {
189+ auto_update_anchor = true ;
190+ } else {
191+ if ( typeof auto_update_anchor !== "boolean" ) {
192+ throw new Error ( "Invalid auto_update_anchor: auto_update_anchor must be a boolean." ) ;
193+ }
194+ }
195+
196+ return { anchor_ids, anchor_labels, anchor_icons, force_anchor, key, orientation, override_styles, auto_update_anchor } ;
179197 }
180198
181199 static getBiName ( icon : string ) {
@@ -228,8 +246,6 @@ class ScrollNavigationBar extends StreamlitComponentBase<State> {
228246 e . currentTarget . style . color = newStyle . color || "" ;
229247 } }
230248 >
231- { /* Render Bootstrap icon if provided */ }
232-
233249 < span >
234250 { anchor_icons && anchor_icons [ index ] && (
235251 < i className = { `${ ScrollNavigationBar . getBiName ( anchor_icons [ index ] ) } ` }
0 commit comments