Skip to content

Select element last element cant be set programatically #2530

@voidpumpkin

Description

@voidpumpkin

Problem

use yew::prelude::*;

#[function_component]
fn App() -> Html {
    let selection_handle = use_state(|| 2_usize);

    html! {
        <div>
            <select >
                <option value=1 selected={*selection_handle == 1}>{ "Option 1" }</option>
                <option value=2 selected={*selection_handle == 2}>{ "Option 2" }</option>
                <option value=3 selected={*selection_handle == 3}>{ "Option 3" }</option>
                <option value=4 selected={*selection_handle == 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>();
}

click "Set to 4"
observe how select shows "Option 1" not 4

Environment:

  • Yew version: [0.19, master]

Questionnaire

  • I'm interested in fixing this myself but don't know where to start
  • I would like to fix and I have a solution
  • [ x] I don't have time to fix this right now, but maybe later

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-yewArea: The main yew cratebug

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions