-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Get Rendered Element Ref (React.createRef()) #115
Comments
Willing to add. Not having it invites cases where elements are called by id etc, which doesn't fit well with the rest of the framework. (Another example of when you'd want it is focusing an element, and other one-off tasks that don't deal with state). One approach: Let the view assign affected elements a key. ( Might not be able to dive in until June. |
Edit on progress: I was able to execute one-off events like this by assigning elements ids, and using fn update(msg: Msg, model: &mut Model, _: &mut Orders<Msg>) {
match msg {
Msg::Focus(id) => {
seed::document()
.get_element_by_id(id)
.expect("Can't find by id")
.dyn_ref::<web_sys::HtmlInputElement>()
.expect("Can't cast as input element")
.focus();
},
//...
}
} It's bad because it's verbose, because it involves manual DOM access and manipulation, and because it may be difficult to assign ids to dynamic elements. May need to pass the top VDOM element, or |
Another use case for getting a ref to the rendered elements is rendering charts to a Canvas element, using |
There is a new API This API should cover the most cases where you need to get DOM elements, draw on canvas, set focus, etc. And I can't find a real-world example, where something like |
Well, I found a case in one of my projects, where it would be nice to use <div class="my-button btn-wrapper">
<div class="btn">Click me</div>
</div> And you want to set focus on the inner element with class
There is
|
@tiberiusferreira References have been implemented (PR #330) and merged into |
Yes it does. Fantastic work! |
Hello, I've seen other issues which wanted a similar thing such as #75.
For a project in React I was implementing a chat and I had to "auto-scroll" to the last message when I got a new one. I did this by using:
I'm sure there are other use cases for getting a ref to the rendered element.
I think this could be implemented now manually by hooking into the did_mount and manually storing the Node information, but would be nice to see a more ergonomic way of doing it.
I don't have a solution in mind yet, I just wanted to see if this is something Seed would want to implement.
The text was updated successfully, but these errors were encountered: