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

[REF-2196] Create rx.scroll_to special event #2834

Closed
picklelo opened this issue Mar 11, 2024 · 6 comments · Fixed by #2948
Closed

[REF-2196] Create rx.scroll_to special event #2834

picklelo opened this issue Mar 11, 2024 · 6 comments · Fixed by #2948
Labels
feature request A feature you wanted added to reflex good first issue Good for newcomers

Comments

@picklelo
Copy link
Contributor

picklelo commented Mar 11, 2024

We should have a special event handler called rx.scroll_to("id") that will scroll to the element with the given id.

The current way to accomplish this is

rx.call_script(f"document.getElementById('{id}').scrollIntoView();")

But there should be a simpler API that wraps this.

REF-2196

@picklelo picklelo added good first issue Good for newcomers feature request A feature you wanted added to reflex labels Mar 11, 2024
@picklelo picklelo changed the title Create rx.scroll_to special event [REF-2196] Create rx.scroll_to special event Mar 11, 2024
@Yummy-Yums
Copy link
Contributor

Yummy-Yums commented Mar 12, 2024

@picklelo which folder/module does this special event go to? is it the same as rx.console_log ?

@picklelo
Copy link
Contributor Author

@Yummy-Yums yes we can put it in the same folder. I'm thinking this can maybe just be an alias that returns the call_script above (i.e. we don't need to modify anything in the Javascript side).

@Yummy-Yums
Copy link
Contributor

Yummy-Yums commented Mar 13, 2024 via email

@picklelo
Copy link
Contributor Author

picklelo commented Mar 13, 2024

The ID should be enough for now (we can add more fancy stuff later). You can see here for an example of how I've used this: https://github.com/picklelo/reflex-chat/blob/main/custom_components/reflex_chat/chat.py#L75

@Yummy-Yums
Copy link
Contributor

Yummy-Yums commented Mar 19, 2024

@picklelo quick one, I intended to use the latter but based on our example above, a simple return call_script will work but that already returns an EventSpec , so how will the fn_name/signature be seen on the js side?

Also, will tests be necessary for this one event action?
image

@picklelo
Copy link
Contributor Author

@Yummy-Yums the way you have it in your PR is exactly what I was thinking, we don't need anything on the js side for this function. Will review your PR this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A feature you wanted added to reflex good first issue Good for newcomers
Projects
None yet
3 participants