Skip to content

Commit 352c2ce

Browse files
committed
Chain onSubmit handlers (running outermost ones first to match SwiftUI)
1 parent aff908a commit 352c2ce

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Sources/SwiftCrossUI/Modifiers/OnSubmitModifier.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
extension View {
22
/// Adds an action to perform when the user submits a text field within this
3-
/// view (generally via pressing the Enter/Return key).
3+
/// view (generally via pressing the Enter/Return key). Outer `onSubmit`
4+
/// handlers get called before inner `onSubmit` handlers. To prevent
5+
/// submissions from propagating upwards, use ``View/submitScope()`` after
6+
/// adding the handler.
47
public func onSubmit(perform action: @escaping () -> Void) -> some View {
58
EnvironmentModifier(self) { environment in
6-
environment.with(\.onSubmit, action)
9+
environment.with(\.onSubmit) {
10+
environment.onSubmit?()
11+
action()
12+
}
713
}
814
}
915

0 commit comments

Comments
 (0)