This commit is contained in:
Aakiyaru 2025-05-27 20:17:15 +07:00
parent 55701d549c
commit 7a4584544b
2 changed files with 6 additions and 3 deletions

View File

@ -15,7 +15,7 @@ struct SelectTestView: View {
} }
var body: some View { var body: some View {
SelectView(title: "Пол", variants: variantds) SelectView(title: "Пол", text: .constant(""), variants: variantds)
} }
} }

View File

@ -10,10 +10,12 @@ import SwiftUI
public struct SelectView: View { public struct SelectView: View {
@State var title: String @State var title: String
@Binding var text: String
let variants: [String] let variants: [String]
public init(title: String, variants: [String]) { public init(title: String, text: Binding<String>, variants: [String]) {
self.title = title self.title = title
self._text = text
self.variants = variants self.variants = variants
} }
@ -23,6 +25,7 @@ public struct SelectView: View {
ForEach(variants, id: \.self) { variant in ForEach(variants, id: \.self) { variant in
Button(variant) { Button(variant) {
title = variant title = variant
text = variant
} }
} }
@ -55,5 +58,5 @@ public struct SelectView: View {
} }
#Preview { #Preview {
SelectView(title: "Пол", variants: ["Male", "Female", "gay"]) SelectView(title: "Пол", text: .constant(""), variants: ["Male", "Female", "gay"])
} }