struct ComboBox
Swift
struct ComboBox<Tag> where Tag : Hashable
A closed field showing the current choice, and a dropdown of the rest.
The list is an overlay(alignment: .below), so it paints above everything,
escapes any surrounding clip, and takes input before the view underneath —
the three things a dropdown needs and a normal child cannot have. Clicking
away, or Escape, dismisses it through the same path menus use; nothing here
tracks that itself.
@State private var tab = 0
ComboBox(
selection: $tab,
items: docs.enumerated().map {
ComboBoxItem($0.element.name, tag: $0.offset, detail: $0.element.path)
},
width: .pt(240)
)
Mouse-driven only: there is no keyboard focus ring or arrow-key navigation
yet, because a composed view has no way to hold focus — that belongs to the
leaf nodes (TextField, EditorView) and would have to grow a focusable
container first.
Sources/LavaUI/ComboBox.swift:56
Constructors
init(selection: Binding<Tag>, items: [ComboBoxItem<Tag>], placeholder: String = "—", width: Dimension = .auto, maxVisibleRows: Int = 10)
Creates a combo box. Every parameter matches the property of the same name.
Sources/LavaUI/ComboBox.swift:74
Properties
var body: some View { get }
Not documented.
Sources/LavaUI/ComboBox.swift:88
var items: [ComboBoxItem<Tag>]
The choices, in the order they are listed.
Sources/LavaUI/ComboBox.swift:60
var maxVisibleRows: Int
Rows shown before the list starts scrolling.
Sources/LavaUI/ComboBox.swift:69
var placeholder: String
Shown when nothing matches selection — an empty list, or a tag that
was removed from under the binding.
Sources/LavaUI/ComboBox.swift:63
@Binding var selection: Tag { get nonmutating set }
The selected tag. Picking a row writes that row's tag here.
Sources/LavaUI/ComboBox.swift:58
var width: Dimension
Width of the closed field. .auto sizes to the current title, which
makes the field jump as the choice changes; a fixed width is usually
what a switcher wants.
Sources/LavaUI/ComboBox.swift:67