From 0842f23d525ed2967ae056e20159712f1cbb29c1 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Sat, 22 Jul 2023 19:21:29 +0200 Subject: [PATCH] Keep the new keyword field focused --- .../Sources/Account/Filters/EditFilterView.swift | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Packages/Account/Sources/Account/Filters/EditFilterView.swift b/Packages/Account/Sources/Account/Filters/EditFilterView.swift index 321dadf5..70f9601c 100644 --- a/Packages/Account/Sources/Account/Filters/EditFilterView.swift +++ b/Packages/Account/Sources/Account/Filters/EditFilterView.swift @@ -20,7 +20,12 @@ struct EditFilterView: View { @State private var filterAction: ServerFilter.Action @State private var expiresAt: Date? @State private var expirySelection: Duration - @FocusState private var isTitleFocused: Bool + + enum Fields { + case title, newKeyword + } + + @FocusState private var focusedField: Fields? private var data: ServerFilterData { var expiresIn: String? @@ -71,7 +76,7 @@ struct EditFilterView: View { .background(theme.secondaryBackgroundColor) .onAppear { if filter == nil { - isTitleFocused = true + focusedField = .title } } .toolbar { @@ -107,7 +112,7 @@ struct EditFilterView: View { private var titleSection: some View { Section("filter.edit.title") { TextField("filter.edit.title", text: $title) - .focused($isTitleFocused) + .focused($focusedField, equals: .title) .onSubmit { Task { await saveFilter() @@ -164,10 +169,12 @@ struct EditFilterView: View { } HStack { TextField("filter.edit.keywords.add", text: $newKeyword, axis: .horizontal) + .focused($focusedField, equals: .newKeyword) .onSubmit { Task { await addKeyword(name: newKeyword) newKeyword = "" + focusedField = .newKeyword } } Spacer()