From 5ab86c070317de35986d9670f14778c7c2b53e3c Mon Sep 17 00:00:00 2001 From: Nikhil Rao Date: Wed, 30 Oct 2024 16:23:15 -0700 Subject: [PATCH] Add option to scroll to bottom --- reflex/event.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/reflex/event.py b/reflex/event.py index aa366e3bb..1cede01c5 100644 --- a/reflex/event.py +++ b/reflex/event.py @@ -767,17 +767,17 @@ def set_focus(ref: str) -> EventSpec: ) -def scroll_to(elem_id: str) -> EventSpec: +def scroll_to(elem_id: str, align_to_top: bool | Var[bool] = True) -> EventSpec: """Select the id of a html element for scrolling into view. Args: - elem_id: the id of the element + elem_id: The id of the element to scroll to. + align_to_top: Whether to scroll to the top (True) or bottom (False) of the element. Returns: An EventSpec to scroll the page to the selected element. """ - js_code = f"document.getElementById('{elem_id}').scrollIntoView();" - + js_code = f"document.getElementById('{elem_id}').scrollIntoView({str(Var.create(align_to_top))});" return call_script(js_code)