Add keyboard dismiss toolbar for iOS numeric and multi-line fields

Creates a reusable KeyboardDismissToolbar view modifier that adds a
"Done" button to dismiss keyboards that don't have a return key.
Applied to all numeric keyboards (numberPad, decimalPad, phonePad)
and multi-line text inputs (TextEditor, TextField with axis: .vertical).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Trey t
2025-12-15 21:20:33 -06:00
parent e44bcdd988
commit e7c09f687a
9 changed files with 44 additions and 0 deletions
@@ -0,0 +1,28 @@
import SwiftUI
/// A view modifier that adds a keyboard toolbar with a "Done" button to dismiss the keyboard.
/// Use this for numeric keyboards (.numberPad, .decimalPad, .phonePad) and multi-line text fields
/// that don't have a return key for dismissal.
struct KeyboardDismissToolbar: ViewModifier {
func body(content: Content) -> some View {
content
.toolbar {
ToolbarItemGroup(placement: .keyboard) {
Spacer()
Button("Done") {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
.foregroundColor(Color.appPrimary)
.fontWeight(.medium)
}
}
}
}
extension View {
/// Adds a keyboard toolbar with a "Done" button to dismiss the keyboard.
/// Use this for numeric keyboards and multi-line text fields.
func keyboardDismissToolbar() -> some View {
modifier(KeyboardDismissToolbar())
}
}