Scroll to feature (#2948)

* updated watchdog dep

* added scroll_to feature

* Fix pre-commit and pyi issues

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
This commit is contained in:
Yummy-Yums 2024-03-29 00:18:08 +00:00 committed by GitHub
parent 8ef193809c
commit e2eced79b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 0 deletions

View File

@ -142,6 +142,7 @@ _MAPPING = {
"remove_local_storage",
"set_clipboard",
"set_focus",
"scroll_to",
"set_value",
"stop_propagation",
"upload_files",

View File

@ -124,6 +124,7 @@ from reflex.event import remove_cookie as remove_cookie
from reflex.event import remove_local_storage as remove_local_storage
from reflex.event import set_clipboard as set_clipboard
from reflex.event import set_focus as set_focus
from reflex.event import scroll_to as scroll_to
from reflex.event import set_value as set_value
from reflex.event import stop_propagation as stop_propagation
from reflex.event import upload_files as upload_files

View File

@ -443,6 +443,20 @@ def set_focus(ref: str) -> EventSpec:
)
def scroll_to(elem_id: str) -> EventSpec:
"""Select the id of a html element for scrolling into view.
Args:
elem_id: the id 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)
def set_value(ref: str, value: Any) -> EventSpec:
"""Set the value of a ref.