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:48
Constructors
init(selection: Binding<Tag>, items: [ComboBoxItem<Tag>], placeholder: String = "—", width: Dimension = .auto, maxVisibleRows: Int = 10)
Not documented.
Sources/LavaUI/ComboBox.swift:63
Properties
var body: some View { get }
Not documented.
Sources/LavaUI/ComboBox.swift:77
var items: [ComboBoxItem<Tag>]
Not documented.
Sources/LavaUI/ComboBox.swift:50
var maxVisibleRows: Int
Rows shown before the list starts scrolling.
Sources/LavaUI/ComboBox.swift:59
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:53
@Binding var selection: Tag { get nonmutating set }
Not documented.
Sources/LavaUI/ComboBox.swift:49
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:57