Commit 84b0864 1 parent e5e4941 commit 84b0864 Copy full SHA for 84b0864
File tree 1 file changed +12
-5
lines changed
1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -767,18 +767,25 @@ def set_focus(ref: str) -> EventSpec:
767
767
)
768
768
769
769
770
- def scroll_to (elem_id : str ) -> EventSpec :
770
+ def scroll_to (elem_id : str , align_to_top : bool | Var [ bool ] = True ) -> EventSpec :
771
771
"""Select the id of a html element for scrolling into view.
772
772
773
773
Args:
774
- elem_id: the id of the element
774
+ elem_id: The id of the element to scroll to.
775
+ align_to_top: Whether to scroll to the top (True) or bottom (False) of the element.
775
776
776
777
Returns:
777
778
An EventSpec to scroll the page to the selected element.
778
779
"""
779
- js_code = f"document.getElementById('{ elem_id } ').scrollIntoView();"
780
-
781
- return call_script (js_code )
780
+ get_element_by_id = FunctionStringVar .create ("document.getElementById" )
781
+
782
+ return call_script (
783
+ get_element_by_id (elem_id )
784
+ .call (elem_id )
785
+ .to (ObjectVar )
786
+ .scrollIntoView .to (FunctionVar )
787
+ .call (align_to_top )
788
+ )
782
789
783
790
784
791
def set_value (ref : str , value : Any ) -> EventSpec :
You can’t perform that action at this time.
0 commit comments