Improve the loading button (#170)

* Set the background opacity when loading
* Do not trigger the on click event when loading
This commit is contained in:
Floyd Wang 2024-08-21 10:57:41 +08:00 committed by GitHub
parent 36354cc5e4
commit 7e9d79ca1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -342,7 +342,7 @@ impl RenderOnce for Button {
}) })
.when(focused, |this| this.border_color(cx.theme().ring)) .when(focused, |this| this.border_color(cx.theme().ring))
.when_some( .when_some(
self.on_click.filter(|_| !self.disabled), self.on_click.filter(|_| !self.disabled && !self.loading),
|this, on_click| { |this, on_click| {
this.on_mouse_down(MouseButton::Left, |_, cx| { this.on_mouse_down(MouseButton::Left, |_, cx| {
cx.prevent_default(); cx.prevent_default();
@ -383,6 +383,7 @@ impl RenderOnce for Button {
.when_some(self.label, |this, label| this.child(label)) .when_some(self.label, |this, label| this.child(label))
.children(self.children) .children(self.children)
}) })
.when(self.loading, |this| this.bg(normal_style.bg.opacity(0.8)))
} }
} }