@@ -41,6 +41,7 @@ pub struct ComboBox<
4141 selection : text_input:: Value ,
4242 on_selected : Box < dyn Fn ( T ) -> Message > ,
4343 on_option_hovered : Option < Box < dyn Fn ( T ) -> Message > > ,
44+ on_open : Option < Message > ,
4445 on_close : Option < Message > ,
4546 on_input : Option < Box < dyn Fn ( String ) -> Message > > ,
4647 menu_class : <Theme as menu:: Catalog >:: Class < ' a > ,
7778 on_selected : Box :: new ( on_selected) ,
7879 on_option_hovered : None ,
7980 on_input : None ,
81+ on_open : None ,
8082 on_close : None ,
8183 menu_class : <Theme as Catalog >:: default_menu ( ) ,
8284 padding : text_input:: DEFAULT_PADDING ,
@@ -104,6 +106,13 @@ where
104106 self
105107 }
106108
109+ /// Sets the message that will be produced when the [`ComboBox`] is
110+ /// opened.
111+ pub fn on_open ( mut self , message : Message ) -> Self {
112+ self . on_open = Some ( message) ;
113+ self
114+ }
115+
107116 /// Sets the message that will be produced when the outside area
108117 /// of the [`ComboBox`] is pressed.
109118 pub fn on_close ( mut self , message : Message ) -> Self {
@@ -632,15 +641,19 @@ where
632641 text_input_state. is_focused ( )
633642 } ;
634643
635- if started_focused && !is_focused && !published_message_to_shell {
636- if let Some ( message) = self . on_close . take ( ) {
637- shell. publish ( message) ;
638- }
639- }
640-
641- // Focus changed, invalidate widget tree to force a fresh `view`
642644 if started_focused != is_focused {
645+ // Focus changed, invalidate widget tree to force a fresh `view`
643646 shell. invalidate_widgets ( ) ;
647+
648+ if !published_message_to_shell {
649+ if is_focused {
650+ if let Some ( on_open) = self . on_open . take ( ) {
651+ shell. publish ( on_open) ;
652+ }
653+ } else if let Some ( on_close) = self . on_close . take ( ) {
654+ shell. publish ( on_close) ;
655+ }
656+ }
644657 }
645658
646659 event_status
0 commit comments