-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Select element last element cant be set programatically #2530
Comments
On MDN it says Its possible we need to introduce custom yew attribute for select so we could pass |
Related? #1322 |
i dont think so |
For now this bug can be worked around: use web_sys::HtmlSelectElement;
use yew::prelude::*;
#[function_component]
fn App() -> Html {
let selection_handle = use_state(|| 2_usize);
let select_node_ref = use_node_ref();
{
let select_node_ref = select_node_ref.clone();
use_effect_with_deps(
move |selection| {
if let Some(element) = select_node_ref.cast::<HtmlSelectElement>() {
element.set_value(&(selection.to_string()));
}
|| {}
},
*selection_handle,
)
};
html! {
<div>
<select ref={select_node_ref}>
<option value=1>{ "Option 1" }</option>
<option value=2>{ "Option 2" }</option>
<option value=3>{ "Option 3" }</option>
<option value=4>{ "Option 4" }</option>
</select>
<button onclick={ {let selection_handle = selection_handle.clone(); Callback::from(move |_| selection_handle.set(1))} }>{"Set to 1"}</button>
<button onclick={ {let selection_handle = selection_handle.clone(); Callback::from(move |_| selection_handle.set(2))} }>{"Set to 2"}</button>
<button onclick={ {let selection_handle = selection_handle.clone(); Callback::from(move |_| selection_handle.set(3))} }>{"Set to 3"}</button>
<button onclick={ {let selection_handle = selection_handle.clone(); Callback::from(move |_| selection_handle.set(4))} }>{"Set to 4"}</button>
</div>
}
}
fn main() {
yew::start_app::<App>();
} |
Going by your fix of calling set_value, I'd say it is related |
Problem
click "Set to 4"
observe how select shows "Option 1" not 4
Environment:
0.19
,master
]Questionnaire
The text was updated successfully, but these errors were encountered: