Skip to content

Commit cc78f34

Browse files
committed
Prevent triggering when button is disabled
1 parent 3b8258a commit cc78f34

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Sources/ButtonKit/Button+Async.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public struct AsyncButton<P: TaskProgress, S: View>: View {
3434
private var allowsHitTestingWhenLoading
3535
@Environment(\.disabledWhenLoading)
3636
private var disabledWhenLoading
37+
@Environment(\.isEnabled)
38+
private var isEnabled
3739
@Environment(\.throwableButtonStyle)
3840
private var throwableButtonStyle
3941
@Environment(\.triggerButton)
@@ -108,7 +110,7 @@ public struct AsyncButton<P: TaskProgress, S: View>: View {
108110
}
109111

110112
private func perform() {
111-
guard task == nil else {
113+
guard task == nil, isEnabled else {
112114
return
113115
}
114116
task = Task {

Sources/ButtonKit/Button+Throwable.swift

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import SwiftUI
2929

3030
public struct ThrowableButton<S: View>: View {
31+
@Environment(\.isEnabled)
32+
private var isEnabled
3133
@Environment(\.throwableButtonStyle)
3234
private var throwableButtonStyle
3335
@Environment(\.triggerButton)
@@ -81,6 +83,9 @@ public struct ThrowableButton<S: View>: View {
8183
}
8284

8385
private func perform() {
86+
guard isEnabled else {
87+
return
88+
}
8489
do {
8590
try action()
8691
} catch {

0 commit comments

Comments
 (0)