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

How to use these components if event handlers are not implemented? #41

Closed
kingsleyh opened this issue Feb 1, 2023 · 3 comments
Closed

Comments

@kingsleyh
Copy link

Hi

Could someone put an example of how to use these components with events? e.g.

 <MatTextField label="Search" value={(*search_query).clone()} >

As the user types I want to take the value from the text input and write into an H1 element below the text field

with a regular input field I would do like this - could someone put an example using this MatTextField componet?

 let search_query = use_state(String::new);

 let oninput = {
        let sq = search_query.clone();
        Callback::from(move |e: InputEvent| {
            let input: HtmlInputElement = e.target_unchecked_into();
            sq.set(input.value());
        })
    };

 yew::html! {
 <div>
   <input type="text" value={(*search_query).clone()} placeholder="Search" {oninput}/>
<h1>{ &*search_query }</h1>
</div>
 }

Any help appreciated

@ranile
Copy link
Owner

ranile commented Feb 10, 2023

Duplicate of #10.

Unfortunately, there's no good solution to this -- the best you could really do is wrap the component in a <span>

@ranile ranile closed this as not planned Won't fix, can't repro, duplicate, stale Feb 10, 2023
@kingsleyh
Copy link
Author

It did not work to wrap in a span for the onInput event unfortunately - the component didn't get all the value just the last few characters typed

@ranile
Copy link
Owner

ranile commented Feb 11, 2023

Oh sorry, I didn't see the oninput event. You can use the oninput prop: https://docs.rs/material-yew/latest/material_yew/text_inputs/struct.TextFieldProps.html#structfield.oninput

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants