Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to scroll to bottom #4276

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions reflex/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,18 +767,25 @@ 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();"

return call_script(js_code)
get_element_by_id = FunctionStringVar.create("document.getElementById")

return call_script(
get_element_by_id(elem_id)
.call(elem_id)
.to(ObjectVar)
.scrollIntoView.to(FunctionVar)
.call(align_to_top)
)


def set_value(ref: str, value: Any) -> EventSpec:
Expand Down
Loading