Backpack-SwiftUI/Select
Day | Night |
---|---|
![]() |
![]() |
![]() |
![]() |
Usage
Create a BPKSelect and pass a placeholder: String , a set of options: [String] and provide the selectedIndex property as a Binding<Int?>. If you want to show the placeholder text, provide a selectedIndex that is initially bound to nil
Select Showing Placeholder
@State var selection: Int? = nil
@State var choices = ["Item 1", "Item 2", "Item 3"]
BPKSelect(placeholder: "Placeholder",
options: choices,
selectedIndex: $selection)
Select With Item Selected
@State var selection: Int? = 0
@State var choices = ["Item 1", "Item 2", "Item 3"]
BPKSelect(placeholder: "Placeholder",
options: choices,
selectedIndex: $selection)
Observe the Selection
BPKSelect(placeholder: "Placeholder",
options: choices,
selectedIndex: $selection)
.onChange(of: selection) { index in
print("Selection changed: \(index)")
}
Changing the State
BPKSelect(placeholder: "List Error State",
options: badChoices,
selectedIndex: $errorSelection)
.inputState(.error)