07-19-2023, 12:05 AM
# Keyboard's `Return` Key
In addition to all answers about tapping outside of the textField, you may want to dismiss the keyboard when the user taps the return key on the keyboard:
define this global function:
```
func resignFirstResponder() {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
```
And add use in `onCommit` argument it:
```
TextField("title", text: $text, onCommit: {
resignFirstResponder()
})
```
### Benefits
- You can call it from anywhere
- It's not dependent on UIKit or SwiftUI (can be used in mac apps)
- It works even in iOS 13
### Demo
![demo][1]
[1]:
In addition to all answers about tapping outside of the textField, you may want to dismiss the keyboard when the user taps the return key on the keyboard:
define this global function:
```
func resignFirstResponder() {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
```
And add use in `onCommit` argument it:
```
TextField("title", text: $text, onCommit: {
resignFirstResponder()
})
```
### Benefits
- You can call it from anywhere
- It's not dependent on UIKit or SwiftUI (can be used in mac apps)
- It works even in iOS 13
### Demo
![demo][1]
[1]: