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

I don't understand how to receive the value of a Slider #17

Open
mwberry opened this issue Feb 6, 2022 · 2 comments
Open

I don't understand how to receive the value of a Slider #17

mwberry opened this issue Feb 6, 2022 · 2 comments

Comments

@mwberry
Copy link

mwberry commented Feb 6, 2022

I'm very much a novice when it comes to web development, so maybe this is supposed to be self-evident, but I don't understand how to receive the value of a MatSlider when it changes. The slider demo doesn't exercise this functionality at all. I was reading through the source and I can see how the JavaScript event is marshalled into a CustomEvent holding an InputEvent. However I can't figure out to access the current value of the slider from within the update method. The CustomEvent::detail method returns a JsValue which should be an InputEvent. I figured out how to cast that. But I expected the InputEvent::detail to contain an integer, but it's always zero. Or maybe InputEvent::data, except that's always None. Maybe the cast didn't really work an I'm just getting Default::default()?

I'm probably missing something important because I feel like I shouldn't be diving into web_sys just to get the current value of a slider.

A quick illustration would clarify a lot. Thanks.

@dirkvdb
Copy link

dirkvdb commented Jun 25, 2022

I have the same issue...

@ranile
Copy link
Owner

ranile commented Jun 25, 2022

Hi, sorry for the late response.

The material-web components used by this library are quite old. There have been breaking changes and I haven't had the time to dedicate to fixing things up. As mentioned in the issue linked in MatSlider's documentation, the component was re-written. I don't know if the new component will work out of the box.

Right now, you can find out how to handle this by logging the value of event passed to console (see gloo-console::log!). You can find out the name of the property which has the slider's value and access it from the CustomEvent.

Here's an example of how to use the CustomEvent::detail() property:

https://github.com/hamza1311/material-yew/blob/70721c1c6bebb716aa8654f45c1ef4f67463fb0c/material-yew/src/list/action_detail.rs#L15-L31

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

3 participants