Repository: iced-rs/iced (language: rust)

Issue:
Unable to register on_open event for combo box
### Is there an existing issue for this?

- [X] I have searched the existing issues.

### Is this issue related to iced?

- [X] My hardware is compatible and my graphics drivers are up-to-date.

### What happened?

I can only register `on_close event, but not `on_open` event.
It's useful to refresh items when combo box is selected.

Currently I can use `on_option_hovered`, but it triggers everytime mouse move over an option

### What is the expected behavior?

ComboBox::new().on_open

### Version

crates.io release

### Operating System

Windows

### Do you have any log output?

_No response_


Discussion / hints:
Hi @WZ-Tong,

I have submitted a PR to add the new feature.

Fix patch:
diff --git a/widget/src/combo_box.rs b/widget/src/combo_box.rs
index 62785b2c39..a51701ca61 100644
--- a/widget/src/combo_box.rs
+++ b/widget/src/combo_box.rs
@@ -41,6 +41,7 @@ pub struct ComboBox<
     selection: text_input::Value,
     on_selected: Box<dyn Fn(T) -> Message>,
     on_option_hovered: Option<Box<dyn Fn(T) -> Message>>,
+    on_open: Option<Message>,
     on_close: Option<Message>,
     on_input: Option<Box<dyn Fn(String) -> Message>>,
     menu_class: <Theme as menu::Catalog>::Class<'a>,
@@ -77,6 +78,7 @@ where
             on_selected: Box::new(on_selected),
             on_option_hovered: None,
             on_input: None,
+            on_open: None,
             on_close: None,
             menu_class: <Theme as Catalog>::default_menu(),
             padding: text_input::DEFAULT_PADDING,
@@ -104,6 +106,13 @@ where
         self
     }
 
+    /// Sets the message that will be produced when the  [`ComboBox`] is
+    /// opened.
+    pub fn on_open(mut self, message: Message) -> Self {
+        self.on_open = Some(message);
+        self
+    }
+
     /// Sets the message that will be produced when the outside area
     /// of the [`ComboBox`] is pressed.
     pub fn on_close(mut self, message: Message) -> Self {
@@ -632,15 +641,19 @@ where
             text_input_state.is_focused()
         };
 
-        if started_focused && !is_focused && !published_message_to_shell {
-            if let Some(message) = self.on_close.take() {
-                shell.publish(message);
-            }
-        }
-
-        // Focus changed, invalidate widget tree to force a fresh `view`
         if started_focused != is_focused {
+            // Focus changed, invalidate widget tree to force a fresh `view`
             shell.invalidate_widgets();
+
+            if !published_message_to_shell {
+                if is_focused {
+                    if let Some(on_open) = self.on_open.take() {
+                        shell.publish(on_open);
+                    }
+                } else if let Some(on_close) = self.on_close.take() {
+                    shell.publish(on_close);
+                }
+            }
         }
 
         event_status


Test patch: