From 0dc329894218500c38e30202182b560b81019ae0 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Fri, 24 Apr 2020 10:30:23 -0400 Subject: [PATCH] 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)