// // TagBarView.swift // Todos // // Created by Sam Jaffe on 2/28/26. // import SwiftUI struct TagBarView: View { @Binding var tags: [Tag] @State private var active: String = "" @FocusState private var isFocused: Bool var body: some View { HStack { ForEach($tags) { tag in TextField("", text: tag.id) .focused($isFocused) .onChange(of: isFocused) { tags.removeAll(where: { $0.id.isEmpty }) } } .scaledToFit() TextField("Tag", text: $active) .onSubmit { if !tags.contains(where: { $0.id.caseInsensitiveCompare(active) == .orderedSame }) { tags.append(Tag(id: active)) } active = "" } } } } #Preview { @Previewable @State var tags = Array() TagBarView(tags: $tags) }