feat: auto-focus search field when Quick Add opens in sheet
All checks were successful
Security Checks / dependency-audit (push) Successful in 13s
Security Checks / secret-scanning (push) Successful in 4s
Security Checks / dockerfile-lint (push) Successful in 4s

Keyboard appears automatically when opening Quick Add from the
food assistant sheet. 300ms delay lets the sheet animation finish
first so the keyboard doesn't interfere with the presentation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Yusuf Suleman
2026-04-04 12:02:39 -05:00
parent 0a10d297cd
commit bf2ff59ade

View File

@@ -5,6 +5,7 @@ struct FoodSearchView: View {
var onFoodAdded: (() -> Void)? var onFoodAdded: (() -> Void)?
@State private var vm = FoodSearchViewModel() @State private var vm = FoodSearchViewModel()
@State private var selectedFood: Food? @State private var selectedFood: Food?
@FocusState private var searchFocused: Bool
var body: some View { var body: some View {
VStack(spacing: 0) { VStack(spacing: 0) {
@@ -15,6 +16,7 @@ struct FoodSearchView: View {
TextField("Search foods...", text: $vm.searchText) TextField("Search foods...", text: $vm.searchText)
.textFieldStyle(.plain) .textFieldStyle(.plain)
.autocorrectionDisabled() .autocorrectionDisabled()
.focused($searchFocused)
if !vm.searchText.isEmpty { if !vm.searchText.isEmpty {
Button { Button {
vm.searchText = "" vm.searchText = ""
@@ -44,6 +46,11 @@ struct FoodSearchView: View {
.background(Color.canvas) .background(Color.canvas)
.task { .task {
await vm.loadInitial() await vm.loadInitial()
if isSheet {
// Small delay so sheet animation completes first
try? await Task.sleep(for: .milliseconds(300))
searchFocused = true
}
} }
.onChange(of: vm.searchText) { .onChange(of: vm.searchText) {
vm.search() vm.search()