pub fn update_text_agent(editing_text: bool) {
    use web_sys::HtmlInputElement;

    let window = match web_sys::window() {
        Some(window) => window,
        None => {
            bevy_log::error!("No window found");
            return;
        }
    };
    let document = match window.document() {
        Some(doc) => doc,
        None => {
            bevy_log::error!("No document found");
            return;
        }
    };
    let input: HtmlInputElement = match document.get_element_by_id(AGENT_ID) {
        Some(ele) => ele,
        None => {
            bevy_log::error!("Agent element not found");
            return;
        }
    }
    .dyn_into()
    .unwrap();

    let keyboard_open = !input.hidden();

    if editing_text {
        // Open the keyboard.
        input.set_hidden(false);
        match input.focus().ok() {
            Some(_) => {}
            None => {
                bevy_log::error!("Unable to set focus");
            }
        }
    } else if keyboard_open {
        // Close the keyboard.
        if input.blur().is_err() {
            bevy_log::error!("Agent element not found");
            return;
        }

        input.set_hidden(true);
    }
}
Focus or blur text agent to toggle mobile keyboard.
src/text_agent.rs