Skip to content

Commit

Permalink
fix: Better input click handling
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed Aug 31, 2024
1 parent f8a0844 commit 0fb6661
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions crates/components/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ pub fn Input(
);
let theme = use_applied_theme!(&theme, input);
let mut focus = use_focus();
let display_placeholder = value.is_empty() && placeholder.is_some() && !focus.is_focused();

let is_focused = focus.is_focused();
let display_placeholder = value.is_empty() && placeholder.is_some() && !is_focused;

if &value != editable.editor().read().rope() {
editable.editor_mut().write().set(&value);
Expand All @@ -119,14 +121,14 @@ pub fn Input(
});

let onkeydown = move |e: Event<KeyboardData>| {
if focus.is_focused() && e.data.key != Key::Enter {
if is_focused && e.data.key != Key::Enter {
editable.process_event(&EditableEvent::KeyDown(e.data));
onchange.call(editable.editor().peek().to_string());
}
};

let onkeyup = move |e: Event<KeyboardData>| {
if focus.is_focused() {
if is_focused {
editable.process_event(&EditableEvent::KeyUp(e.data));
}
};
Expand Down Expand Up @@ -155,6 +157,7 @@ pub fn Input(
let onglobalclick = move |_| match *status.read() {
InputStatus::Idle if focus.is_focused() => {
focus.unfocus();
editable.process_event(&EditableEvent::Click);
}
InputStatus::Hovering => {
editable.process_event(&EditableEvent::Click);
Expand Down

0 comments on commit 0fb6661

Please sign in to comment.