← All Workshops
MudEngine Part 8: Inventory & Chat
Step 10 / 14
Click the chat to focus the input
One small polish: clicking anywhere in the Room Chat panel should focus the command input, so players can read a message and start typing without reaching for the box. We use Dioxus' document::eval escape hatch — a one-liner that runs a browser API call.
mud-engine/src/components/game.rs
// Chat panel div { class: "chat-panel", onclick: move |_| { _ = dioxus::document::eval( "document.querySelector('.command-input')?.focus();", ); }, div { class: "chat-header", "💬 Room Chat" }
💡 Why not a Signal?
Focusing an element is a DOM operation — Dioxus state only re-renders, it can't reach into the browser. document::eval sends a small JavaScript snippet to the live document. It only runs in the browser (or a desktop webview), never during server-side rendering, so it's safe inside an onclick handler which only fires after the page is interactive.
Step 10 / 14