button_group: Fix overriding button click when no on_click (#1546)

When `on_click` is not specified on the button group, this PR allows for
specifying on_click on each individual button.

e.g.

```rs
let buttons = ButtonGroup::new(("buttons", index)).layout(Axis::Vertical)
    .child(Button::new(("install", index)).label("Install").icon(download_icon).success().on_click(move |_, _, cx| {
          // Install
    })
    .child(Button::new(("open", index)).label("Open Page").icon(IconName::Globe).info().on_click(move |_, _, cx| {
         // Open page
    }));
```
This commit is contained in:
Moulberry 2025-11-10 09:43:25 +08:00 committed by GitHub
parent b899100d09
commit a4d792f121
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -219,8 +219,10 @@ impl RenderOnce for ButtonGroup {
.when_some(self.variant, |this, variant| this.with_variant(variant))
.when(self.compact, |this| this.compact())
.when(self.outline, |this| this.outline())
.on_click(move |_, _, _| {
state.set(Some(child_index));
.when(self.on_click.is_some(), |this| {
this.on_click(move |_, _, _| {
state.set(Some(child_index));
})
});
child