Skip to content

Commit

Permalink
fix(keybindings): add js to force a blur on successful keybind change (
Browse files Browse the repository at this point in the history
  • Loading branch information
Jekrimo authored Jan 25, 2024
1 parent 7ce8505 commit c534f88
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ui/src/components/settings/sub_pages/keybinds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ const AVOID_INPUT_ON_DIV: &str = r#"
event.preventDefault();
});"#;

const UNFOCUS_DIV_ON_SUBMIT: &str = r#"
let currentDiv = document.getElementById("$UUID");
let innerDiv = currentDiv.querySelector('.keybind-section-keys');
if (innerDiv.classList.contains('recording')) {
innerDiv.addEventListener('keyup', function() {
innerDiv.blur();
});
}
"#;

#[derive(PartialEq, Props)]
pub struct KeybindProps {
pub keys: Vec<String>, // TODO: This should be a Vec<Key>
Expand Down Expand Up @@ -122,6 +132,18 @@ pub fn KeybindSection(cx: Scope<KeybindSectionProps>) -> Element {
let eval = use_eval(cx);
let script = AVOID_INPUT_ON_DIV.replace("$UUID", keybind_section_id.as_str());
let _ = eval(&script);
let keybind_section_id_clone = keybind_section_id.clone();

use_effect(cx, is_recording, |is_recording| {
to_owned![eval];
async move {
if *is_recording {
let unfocus_script =
UNFOCUS_DIV_ON_SUBMIT.replace("$UUID", keybind_section_id_clone.as_str());
let _ = eval(&unfocus_script);
};
}
});

let mut keybind_class = "keybind-section-keys".to_owned();
if **is_recording {
Expand Down

0 comments on commit c534f88

Please sign in to comment.