refactored to base class and removed more duplicate code
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
c1f2aa6591
commit
652088bbb1
@ -100,8 +100,6 @@ open class DatePicker: EntryFieldBase, DatePickerViewControllerDelegate, UIPopov
|
|||||||
/// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations.
|
/// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations.
|
||||||
open override func setup() {
|
open override func setup() {
|
||||||
super.setup()
|
super.setup()
|
||||||
|
|
||||||
containerView.isAccessibilityElement = true
|
|
||||||
|
|
||||||
// setting color config
|
// setting color config
|
||||||
selectedDateLabel.textColorConfiguration = primaryColorConfiguration.eraseToAnyColorable()
|
selectedDateLabel.textColorConfiguration = primaryColorConfiguration.eraseToAnyColorable()
|
||||||
@ -142,36 +140,7 @@ open class DatePicker: EntryFieldBase, DatePickerViewControllerDelegate, UIPopov
|
|||||||
selectedDateLabel.isEnabled = isEnabled
|
selectedDateLabel.isEnabled = isEnabled
|
||||||
calendarIcon.color = iconColorConfiguration.getColor(self)
|
calendarIcon.color = iconColorConfiguration.getColor(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func updateAccessibility() {
|
|
||||||
super.updateAccessibility()
|
|
||||||
containerView.accessibilityLabel = "Date Picker, \(accessibilityLabelText)"
|
|
||||||
containerView.accessibilityHint = isReadOnly || !isEnabled ? "" : "Double tap to open."
|
|
||||||
containerView.accessibilityValue = value
|
|
||||||
}
|
|
||||||
|
|
||||||
open override var accessibilityElements: [Any]? {
|
|
||||||
get {
|
|
||||||
var elements = [Any]()
|
|
||||||
elements.append(contentsOf: [titleLabel, containerView])
|
|
||||||
|
|
||||||
if showError {
|
|
||||||
elements.append(statusIcon)
|
|
||||||
if let errorText, !errorText.isEmpty {
|
|
||||||
elements.append(errorLabel)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let helperText, !helperText.isEmpty {
|
|
||||||
elements.append(helperLabel)
|
|
||||||
}
|
|
||||||
|
|
||||||
return elements
|
|
||||||
}
|
|
||||||
|
|
||||||
set { super.accessibilityElements = newValue }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Resets to default settings.
|
/// Resets to default settings.
|
||||||
open override func reset() {
|
open override func reset() {
|
||||||
super.reset()
|
super.reset()
|
||||||
|
|||||||
@ -131,7 +131,6 @@ open class DropdownSelect: EntryFieldBase {
|
|||||||
open override func setup() {
|
open override func setup() {
|
||||||
super.setup()
|
super.setup()
|
||||||
|
|
||||||
containerView.isAccessibilityElement = true
|
|
||||||
inlineDisplayLabel.isAccessibilityElement = true
|
inlineDisplayLabel.isAccessibilityElement = true
|
||||||
|
|
||||||
dropdownField.width(0)
|
dropdownField.width(0)
|
||||||
@ -276,36 +275,6 @@ open class DropdownSelect: EntryFieldBase {
|
|||||||
statusIcon.color = iconColorConfiguration.getColor(self)
|
statusIcon.color = iconColorConfiguration.getColor(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func updateAccessibility() {
|
|
||||||
super.updateAccessibility()
|
|
||||||
containerView.accessibilityLabel = "Dropdown Select, \(accessibilityLabelText)"
|
|
||||||
containerView.accessibilityHint = isReadOnly || !isEnabled ? "" : "has popup, Double tap to open."
|
|
||||||
containerView.accessibilityValue = value
|
|
||||||
}
|
|
||||||
|
|
||||||
open override var accessibilityElements: [Any]? {
|
|
||||||
get {
|
|
||||||
var elements = [Any]()
|
|
||||||
elements.append(contentsOf: [titleLabel, containerView])
|
|
||||||
|
|
||||||
if showError {
|
|
||||||
elements.append(statusIcon)
|
|
||||||
if let errorText, !errorText.isEmpty {
|
|
||||||
elements.append(errorLabel)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let helperText, !helperText.isEmpty {
|
|
||||||
elements.append(helperLabel)
|
|
||||||
}
|
|
||||||
|
|
||||||
return elements
|
|
||||||
}
|
|
||||||
|
|
||||||
set { super.accessibilityElements = newValue }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@objc open func pickerDoneClicked() {
|
@objc open func pickerDoneClicked() {
|
||||||
optionsPicker.isHidden = true
|
optionsPicker.isHidden = true
|
||||||
dropdownField.resignFirstResponder()
|
dropdownField.resignFirstResponder()
|
||||||
|
|||||||
@ -95,6 +95,7 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
|
|||||||
internal var containerView: UIView = {
|
internal var containerView: UIView = {
|
||||||
return UIView().with {
|
return UIView().with {
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
$0.isAccessibilityElement = true
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -243,7 +244,8 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
|
|||||||
|
|
||||||
open var accessibilityLabelText: String {
|
open var accessibilityLabelText: String {
|
||||||
var accessibilityLabels = [String]()
|
var accessibilityLabels = [String]()
|
||||||
if let text = titleLabel.text {
|
|
||||||
|
if let text = titleLabel.text?.trimmingCharacters(in: .whitespaces) {
|
||||||
accessibilityLabels.append(text)
|
accessibilityLabels.append(text)
|
||||||
}
|
}
|
||||||
if isReadOnly {
|
if isReadOnly {
|
||||||
@ -255,9 +257,14 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
|
|||||||
if let errorText, showError {
|
if let errorText, showError {
|
||||||
accessibilityLabels.append("error, \(errorText)")
|
accessibilityLabels.append("error, \(errorText)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
accessibilityLabels.append("\(Self.self)")
|
||||||
|
|
||||||
return accessibilityLabels.joined(separator: ", ")
|
return accessibilityLabels.joined(separator: ", ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open var accessibilityHintText: String = "Double tap to open"
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Overrides
|
// MARK: - Overrides
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -447,6 +454,35 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open override func updateAccessibility() {
|
||||||
|
super.updateAccessibility()
|
||||||
|
containerView.accessibilityLabel = accessibilityLabelText
|
||||||
|
containerView.accessibilityHint = isReadOnly || !isEnabled ? "" : accessibilityHintText
|
||||||
|
containerView.accessibilityValue = value
|
||||||
|
}
|
||||||
|
|
||||||
|
open override var accessibilityElements: [Any]? {
|
||||||
|
get {
|
||||||
|
var elements = [Any]()
|
||||||
|
elements.append(contentsOf: [titleLabel, containerView])
|
||||||
|
|
||||||
|
if showError {
|
||||||
|
elements.append(statusIcon)
|
||||||
|
if let errorText, !errorText.isEmpty {
|
||||||
|
elements.append(errorLabel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let helperText, !helperText.isEmpty {
|
||||||
|
elements.append(helperLabel)
|
||||||
|
}
|
||||||
|
|
||||||
|
return elements
|
||||||
|
}
|
||||||
|
|
||||||
|
set { super.accessibilityElements = newValue }
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Private Methods
|
// MARK: - Private Methods
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -102,6 +102,7 @@ open class InputField: EntryFieldBase {
|
|||||||
open var textField = TextField().with {
|
open var textField = TextField().with {
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
$0.textStyle = TextStyle.bodyLarge
|
$0.textStyle = TextStyle.bodyLarge
|
||||||
|
$0.isAccessibilityElement = false
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Color configuration for the textField.
|
/// Color configuration for the textField.
|
||||||
@ -181,8 +182,7 @@ open class InputField: EntryFieldBase {
|
|||||||
/// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations.
|
/// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations.
|
||||||
open override func setup() {
|
open override func setup() {
|
||||||
super.setup()
|
super.setup()
|
||||||
containerView.isAccessibilityElement = true
|
accessibilityHintText = "Double tap to edit"
|
||||||
textField.isAccessibilityElement = false
|
|
||||||
|
|
||||||
textField.heightAnchor.constraint(equalToConstant: 20).isActive = true
|
textField.heightAnchor.constraint(equalToConstant: 20).isActive = true
|
||||||
textField.delegate = self
|
textField.delegate = self
|
||||||
@ -230,14 +230,7 @@ open class InputField: EntryFieldBase {
|
|||||||
textField.isEnabled = isEnabled
|
textField.isEnabled = isEnabled
|
||||||
textField.isUserInteractionEnabled = isEnabled && !isReadOnly
|
textField.isUserInteractionEnabled = isEnabled && !isReadOnly
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func updateAccessibility() {
|
|
||||||
super.updateAccessibility()
|
|
||||||
containerView.accessibilityLabel = "Input Field, \(accessibilityLabelText)"
|
|
||||||
containerView.accessibilityHint = isReadOnly || !isEnabled ? "" : "Double tap to edit."
|
|
||||||
containerView.accessibilityValue = value
|
|
||||||
}
|
|
||||||
|
|
||||||
open override func updateErrorLabel() {
|
open override func updateErrorLabel() {
|
||||||
super.updateErrorLabel()
|
super.updateErrorLabel()
|
||||||
|
|
||||||
|
|||||||
@ -42,14 +42,14 @@ open class TextArea: EntryFieldBase {
|
|||||||
$0.spacing = VDSLayout.space3X
|
$0.spacing = VDSLayout.space3X
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
open var characterCounterLabel = Label().with {
|
open var characterCounterLabel = Label().with {
|
||||||
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
$0.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
$0.textStyle = .bodySmall
|
$0.textStyle = .bodySmall
|
||||||
$0.textAlignment = .right
|
$0.textAlignment = .right
|
||||||
$0.numberOfLines = 1
|
$0.numberOfLines = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
open var minHeight: Height = .twoX { didSet { setNeedsUpdate() } }
|
open var minHeight: Height = .twoX { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -101,13 +101,15 @@ open class TextArea: EntryFieldBase {
|
|||||||
open override var value: String? {
|
open override var value: String? {
|
||||||
return textView.text
|
return textView.text
|
||||||
}
|
}
|
||||||
|
|
||||||
/// UITextView shown in the TextArea.
|
/// UITextView shown in the TextArea.
|
||||||
open var textView = TextView().with {
|
open var textView = TextView().with {
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
$0.sizeToFit()
|
$0.sizeToFit()
|
||||||
$0.isScrollEnabled = false
|
$0.isAccessibilityElement = false
|
||||||
|
$0.isScrollEnabled = true
|
||||||
$0.textContainerInset = .zero
|
$0.textContainerInset = .zero
|
||||||
|
$0.autocorrectionType = .no
|
||||||
$0.textContainer.lineFragmentPadding = 0
|
$0.textContainer.lineFragmentPadding = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,10 +139,8 @@ open class TextArea: EntryFieldBase {
|
|||||||
/// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations.
|
/// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations.
|
||||||
open override func setup() {
|
open override func setup() {
|
||||||
super.setup()
|
super.setup()
|
||||||
containerView.isAccessibilityElement = true
|
|
||||||
textView.isAccessibilityElement = false
|
accessibilityHintText = "Double tap to edit"
|
||||||
textView.isScrollEnabled = true
|
|
||||||
textView.autocorrectionType = .no
|
|
||||||
|
|
||||||
//events
|
//events
|
||||||
textView
|
textView
|
||||||
@ -192,14 +192,7 @@ open class TextArea: EntryFieldBase {
|
|||||||
characterCounterLabel.surface = surface
|
characterCounterLabel.surface = surface
|
||||||
highlightCharacterOverflow()
|
highlightCharacterOverflow()
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func updateAccessibility() {
|
|
||||||
super.updateAccessibility()
|
|
||||||
containerView.accessibilityLabel = "\(Self.self), \(accessibilityLabelText)"
|
|
||||||
containerView.accessibilityHint = isReadOnly || !isEnabled ? "" : "Double tap to open."
|
|
||||||
containerView.accessibilityValue = value
|
|
||||||
}
|
|
||||||
|
|
||||||
override func updateRules() {
|
override func updateRules() {
|
||||||
super.updateRules()
|
super.updateRules()
|
||||||
|
|
||||||
@ -223,30 +216,7 @@ open class TextArea: EntryFieldBase {
|
|||||||
stackView.addArrangedSubview(characterCounterLabel)
|
stackView.addArrangedSubview(characterCounterLabel)
|
||||||
return stackView
|
return stackView
|
||||||
}
|
}
|
||||||
|
|
||||||
open override var accessibilityElements: [Any]? {
|
|
||||||
get {
|
|
||||||
var elements = [Any]()
|
|
||||||
elements.append(contentsOf: [titleLabel, containerView])
|
|
||||||
|
|
||||||
if showError {
|
|
||||||
elements.append(statusIcon)
|
|
||||||
if let errorText, !errorText.isEmpty {
|
|
||||||
elements.append(errorLabel)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let helperText, !helperText.isEmpty {
|
|
||||||
elements.append(helperLabel)
|
|
||||||
}
|
|
||||||
|
|
||||||
return elements
|
|
||||||
}
|
|
||||||
|
|
||||||
set { super.accessibilityElements = newValue }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
open override var canBecomeFirstResponder: Bool {
|
open override var canBecomeFirstResponder: Bool {
|
||||||
return textView.canBecomeFirstResponder
|
return textView.canBecomeFirstResponder
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user