From c0b0b817e83680379a77110ab9885d4b6b31e1c9 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Wed, 26 Mar 2025 16:34:22 +0100 Subject: [PATCH] fix(text_input): send on_unfocus message where they were missing --- src/widget/text_input/input.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/widget/text_input/input.rs b/src/widget/text_input/input.rs index 14938572..47841c06 100644 --- a/src/widget/text_input/input.rs +++ b/src/widget/text_input/input.rs @@ -650,6 +650,7 @@ where if let Some(f) = state.is_focused.as_ref() { if f.updated_at != LAST_FOCUS_UPDATE.with(|f| f.get()) { state.unfocus(); + state.emit_unfocus = true; } } @@ -876,6 +877,16 @@ where } } + let state = tree.state.downcast_mut::(); + + if let Some(on_unfocus) = self.on_unfocus.as_ref() { + if state.emit_unfocus { + state.emit_unfocus = false; + eprintln!("unfocus"); + shell.publish(on_unfocus.clone()); + } + } + let dnd_id = self.dnd_id(); let id = Widget::id(self); update( @@ -1532,6 +1543,10 @@ pub fn update<'a, Message: Clone + 'static>( return event::Status::Captured; } else { state.unfocus(); + + if let Some(on_unfocus) = on_unfocus { + shell.publish(on_unfocus.clone()); + } } } Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left)) @@ -2486,6 +2501,7 @@ pub struct State { pub dirty: bool, pub is_secure: bool, pub is_read_only: bool, + pub emit_unfocus: bool, select_on_focus: bool, is_focused: Option, dragging_state: Option, @@ -2560,6 +2576,7 @@ impl State { label: crate::Plain::default(), helper_text: crate::Plain::default(), is_read_only, + emit_unfocus: false, is_focused: None, select_on_focus: false, dragging_state: None,