Skip to content

Component KeybindingInput

MeowLynxSea edited this page Jun 13, 2026 · 5 revisions

KeybindingInput

A single-line text input that, when in Capturing mode, records the next keystroke as a keybinding combo instead of typing it. Used for "press a key to bind" settings rows.

Import

use yororen_ui::headless::keybinding_input::keybinding_input;
use yororen_ui::headless::keybinding_input::KeybindingInputMode;

Minimal example

use yororen_ui::headless::keybinding_input::{keybinding_input, KeybindingInputMode};

keybinding_input("bind-save")
    .placeholder("Press a key combo…")
    .mode(KeybindingInputMode::Idle)
    .on_start_capture(|_window, _cx| {
        // switch the input into capture mode
    })
    .on_change({
        let entity = cx.entity();
        move |new: &str, _window, cx| {
            entity.update(cx, |s, _cx| s.binding = new.to_string());
        }
    })
    .render(cx, window)

Props

Method Purpose
mode(m) KeybindingInputMode::Idle (default) or KeybindingInputMode::Capturing.
placeholder(text) Hint text shown when empty.
disabled(v) Disable interaction.
on_change(closure) Fn(&str, &mut Window, &mut App) + 'static + Send + Sync. Fired with the captured combo as a string.
on_start_capture(closure) Fn(&mut Window, &mut App) + 'static + Send + Sync. The input is now capturing.
on_cancel_capture(closure) Fn(&mut Window, &mut App) + 'static + Send + Sync. The user dismissed capture (e.g. pressed Escape).

Notes

  • Factory takes (id) only. Like the other text-style inputs, the focus handle and the keyed state are minted by the renderer.
  • .render(cx, window) is two-arg and returns AnyElement. The window is required because the renderer hooks the EntityInputHandler for IME / paste.
  • The mode enum is KeybindingInputMode (not KeybindingMode); it has two variants: Idle (default) and Capturing. There is no Chord variant.
  • on_change and on_start_capture are typically called from a parent view that flips mode(...) between Idle and Capturing in response.

See also

TextInput, ShortcutHint, SearchInput

Clone this wiki locally