From 0dc329894218500c38e30202182b560b81019ae0 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Fri, 24 Apr 2020 10:30:23 -0400 Subject: [PATCH 1/3] adding accessibility state to radio button --- .../Atomic/Atoms/Selectors/RadioButton.swift | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift index 1a968b7a..af1e7905 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift @@ -23,6 +23,7 @@ import UIKit public override var isSelected: Bool { didSet { radioModel?.state = isSelected + updateAccessibilityLabel() } } @@ -118,6 +119,19 @@ import UIKit return radioModel?.fieldValue } + //-------------------------------------------------- + // MARK: - Methods + //-------------------------------------------------- + + /// Adjust accessibility label based on state of RadioButton. + func updateAccessibilityLabel() { + // Attention: This needs to be addressed with the accessibility team. + // NOTE: Currently emptying description part of MVMCoreUICheckBox accessibility label to avoid crashing! + if let state = MVMCoreUIUtility.hardcodedString(withKey: isSelected ? "radio_selected_state" : "radio_not_selected_state") { + accessibilityLabel = String(format: MVMCoreUIUtility.hardcodedString(withKey: "radio_desc_state") ?? "%@%@", "", state) + } + } + //-------------------------------------------------- // MARK: - MVMViewProtocol //-------------------------------------------------- @@ -136,14 +150,15 @@ import UIKit isAccessibilityElement = true accessibilityTraits = .button accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "radio_action_hint") + updateAccessibilityLabel() } public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) + self.delegateObject = delegateObject guard let model = model as? RadioButtonModel else { return } - self.delegateObject = delegateObject isSelected = model.state isEnabled = model.enabled RadioButtonSelectionHelper.setupForRadioButtonGroup(model, self, delegateObject: delegateObject) From 9620548a43030f590025cd6f8fb23a1d1168722d Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Fri, 24 Apr 2020 10:33:14 -0400 Subject: [PATCH 2/3] updates and revision --- .../Atomic/Atoms/Selectors/RadioButton.swift | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift index af1e7905..8d2563d0 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift @@ -19,14 +19,14 @@ import UIKit widthConstraint?.constant = diameter } } - + public override var isSelected: Bool { didSet { radioModel?.state = isSelected updateAccessibilityLabel() } } - + public var enabledColor: UIColor = .mvmBlack public var disabledColor: UIColor = .mvmCoolGray3 public var delegateObject: MVMCoreUIDelegateObject? @@ -40,12 +40,12 @@ import UIKit }() lazy public var radioButtonSelectionHelper: RadioButtonSelectionHelper? = { - if let radioGroupName = radioGroupName, - let radioButtonModel = delegateObject?.formHolderDelegate?.formValidator?.radioButtonsModelByGroup[radioGroupName] { - return radioButtonModel - } else { - return nil - } + + guard let radioGroupName = radioGroupName, + let radioButtonModel = delegateObject?.formHolderDelegate?.formValidator?.radioButtonsModelByGroup[radioGroupName] + else { return nil } + + return radioButtonModel }() public override var isEnabled: Bool { @@ -128,7 +128,7 @@ import UIKit // Attention: This needs to be addressed with the accessibility team. // NOTE: Currently emptying description part of MVMCoreUICheckBox accessibility label to avoid crashing! if let state = MVMCoreUIUtility.hardcodedString(withKey: isSelected ? "radio_selected_state" : "radio_not_selected_state") { - accessibilityLabel = String(format: MVMCoreUIUtility.hardcodedString(withKey: "radio_desc_state") ?? "%@%@", "", state) + accessibilityLabel = String(format: MVMCoreUIUtility.hardcodedString(withKey: "radio_desc_state") ?? "%@%@", "", isSelected) } } From 77811e1f246d98b5f970d2e33539785d5c51658f Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Fri, 24 Apr 2020 16:39:23 -0400 Subject: [PATCH 3/3] revised --- MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift index 8d2563d0..2b22fcee 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioButton.swift @@ -125,10 +125,9 @@ import UIKit /// Adjust accessibility label based on state of RadioButton. func updateAccessibilityLabel() { - // Attention: This needs to be addressed with the accessibility team. - // NOTE: Currently emptying description part of MVMCoreUICheckBox accessibility label to avoid crashing! + if let state = MVMCoreUIUtility.hardcodedString(withKey: isSelected ? "radio_selected_state" : "radio_not_selected_state") { - accessibilityLabel = String(format: MVMCoreUIUtility.hardcodedString(withKey: "radio_desc_state") ?? "%@%@", "", isSelected) + accessibilityLabel = String(format: MVMCoreUIUtility.hardcodedString(withKey: "radio_desc_state") ?? "%@%@", "", state) } }