TagBarView.swift 723 B

12345678910111213141516171819202122232425262728293031323334353637
  1. //
  2. // TagBarView.swift
  3. // Todos
  4. //
  5. // Created by Sam Jaffe on 2/28/26.
  6. //
  7. import SwiftUI
  8. struct TagBarView: View {
  9. @Binding var tags: [Tag]
  10. @State private var active: String = ""
  11. @FocusState private var isFocused: Bool
  12. var body: some View {
  13. HStack {
  14. ForEach($tags) { tag in
  15. TextField("", text: tag.id)
  16. .focused($isFocused)
  17. .onChange(of: isFocused) {
  18. tags.removeAll(where: { $0.id.isEmpty })
  19. }
  20. }
  21. .scaledToFit()
  22. TextField("Tag", text: $active)
  23. .onSubmit {
  24. tags.append(Tag(id: active))
  25. active = ""
  26. }
  27. }
  28. }
  29. }
  30. #Preview {
  31. @Previewable @State var tags = Array<Tag>()
  32. TagBarView(tags: $tags)
  33. }