From 0af79c97b7423979a3a214e706643f4890731366 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 10 May 2024 10:08:10 -0500 Subject: [PATCH] refactored to helpertext to the right Signed-off-by: Matt Bruce --- .../DropdownSelect/DropdownSelect.swift | 12 ++++++++++++ VDS/Components/TextFields/EntryFieldBase.swift | 7 ++++--- .../TextFields/InputField/InputField.swift | 15 +++++++++++++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/VDS/Components/DropdownSelect/DropdownSelect.swift b/VDS/Components/DropdownSelect/DropdownSelect.swift index bb4d2d97..6476819d 100644 --- a/VDS/Components/DropdownSelect/DropdownSelect.swift +++ b/VDS/Components/DropdownSelect/DropdownSelect.swift @@ -92,6 +92,7 @@ open class DropdownSelect: EntryFieldBase { // MARK: - Constraints //-------------------------------------------------- internal var inlineWidthConstraint: NSLayoutConstraint? + internal var titleLabelWidthConstraint: NSLayoutConstraint? //-------------------------------------------------- // MARK: - Configuration Properties @@ -106,6 +107,10 @@ open class DropdownSelect: EntryFieldBase { open override func setup() { super.setup() + titleLabel.setContentCompressionResistancePriority(.required, for: .horizontal) + titleLabel.setContentHuggingPriority(.required, for: .horizontal) + titleLabelWidthConstraint = titleLabel.width(constant: 0) + fieldStackView.isAccessibilityElement = true fieldStackView.accessibilityLabel = "Dropdown Select" inlineDisplayLabel.isAccessibilityElement = true @@ -305,6 +310,13 @@ open class DropdownSelect: EntryFieldBase { setNeedsUpdate() UIAccessibility.post(notification: .layoutChanged, argument: fieldStackView) } + + open override func layoutSubviews() { + super.layoutSubviews() + titleLabelWidthConstraint?.constant = containerView.frame.width + titleLabelWidthConstraint?.isActive = helperTextPlacement == .right + } + } //-------------------------------------------------- diff --git a/VDS/Components/TextFields/EntryFieldBase.swift b/VDS/Components/TextFields/EntryFieldBase.swift index ea833187..0581c4bb 100644 --- a/VDS/Components/TextFields/EntryFieldBase.swift +++ b/VDS/Components/TextFields/EntryFieldBase.swift @@ -58,6 +58,7 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { $0.translatesAutoresizingMaskIntoConstraints = false $0.axis = .vertical $0.distribution = .fill + $0.alignment = .leading } }() @@ -209,7 +210,7 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { //-------------------------------------------------- internal var heightConstraint: NSLayoutConstraint? internal var widthConstraint: NSLayoutConstraint? - + //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- @@ -227,10 +228,10 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { widthConstraint = containerView.widthAnchor.constraint(equalToConstant: 0) widthConstraint?.priority = .defaultHigh - + //add the containerView to the middleStack middleStackView.addArrangedSubview(containerView) - + //add ContainerStackView //this is the horizontal stack that contains //the left, InputContainer, Icons, Buttons diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index 49f0cfbc..62181d69 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -35,7 +35,8 @@ open class InputField: EntryFieldBase { // MARK: - Private Properties //-------------------------------------------------- internal var minWidthConstraint: NSLayoutConstraint? - + internal var titleLabelWidthConstraint: NSLayoutConstraint? + //-------------------------------------------------- // MARK: - Public FieldType Properties //-------------------------------------------------- @@ -167,6 +168,10 @@ open class InputField: EntryFieldBase { open override func setup() { super.setup() + titleLabel.setContentCompressionResistancePriority(.required, for: .horizontal) + titleLabel.setContentHuggingPriority(.required, for: .horizontal) + titleLabelWidthConstraint = titleLabel.width(constant: 0) + minWidthConstraint = containerView.widthAnchor.constraint(greaterThanOrEqualToConstant: 0) minWidthConstraint?.isActive = true @@ -275,7 +280,7 @@ open class InputField: EntryFieldBase { } } } - + override func updateRules() { super.updateRules() fieldType.handler().appendRules(self) @@ -310,6 +315,12 @@ open class InputField: EntryFieldBase { set { super.accessibilityElements = newValue } } + open override func layoutSubviews() { + super.layoutSubviews() + titleLabelWidthConstraint?.constant = containerView.frame.width + titleLabelWidthConstraint?.isActive = helperTextPlacement == .right + } + open override var canBecomeFirstResponder: Bool { true } open override func resignFirstResponder() -> Bool {