From b07c0108883e10cb347dc4074fe32411b9e461cc Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 9 Apr 2024 16:12:24 -0500 Subject: [PATCH] refactored naming Signed-off-by: Matt Bruce --- VDS/Components/DropdownSelect/DropdownSelect.swift | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/VDS/Components/DropdownSelect/DropdownSelect.swift b/VDS/Components/DropdownSelect/DropdownSelect.swift index 94f7112d..a56eb783 100644 --- a/VDS/Components/DropdownSelect/DropdownSelect.swift +++ b/VDS/Components/DropdownSelect/DropdownSelect.swift @@ -38,11 +38,17 @@ open class DropdownSelect: EntryFieldBase { /// Allows unique ID to be passed to the element. open var selectId: Int? { didSet { setNeedsUpdate() }} + /// Current SelectedItem + open var selectedItem: DropdownOptionModel? { + guard let selectId else { return nil } + return options[selectId] + } + /// Array of options to show open var options: [DropdownOptionModel] = [] { didSet { setNeedsUpdate() }} /// A callback when the selected option changes. Passes parameters (option). - open var onDropdownItemSelect: ((DropdownOptionModel) -> Void)? + open var onItemSelected: ((Int, DropdownOptionModel) -> Void)? //-------------------------------------------------- // MARK: - Private Properties @@ -52,7 +58,7 @@ open class DropdownSelect: EntryFieldBase { //-------------------------------------------------- // MARK: - Public Properties - //-------------------------------------------------- + //-------------------------------------------------- open var inlineDisplayLabel = Label().with { $0.textAlignment = .left $0.textStyle = .boldBodyLarge @@ -171,7 +177,7 @@ open class DropdownSelect: EntryFieldBase { selectedOptionLabel.textStyle = .bodyLarge showInlineLabel = false options = [] - selectId = 0 + selectId = nil } //-------------------------------------------------- @@ -279,6 +285,6 @@ extension DropdownSelect: UIPickerViewDelegate, UIPickerViewDataSource { guard options.count > row else { return } selectId = row updateSelectedOptionLabel(option: options[row]) - self.onDropdownItemSelect?(options[row]) + self.onItemSelected?(row, options[row]) } }