feat: auto-focus search field when Quick Add opens in sheet
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:
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user