Digital ACT191 story ONEAPP-6682 added accessibility, focused border color to container

This commit is contained in:
vasavk 2024-02-26 17:02:36 +05:30
parent 5b01027554
commit 72ef366eed

View File

@ -108,6 +108,10 @@ 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()
accessibilityLabel = "TextArea"
isAccessibilityElement = true
containerStackView.pinToSuperView(.uniform(VDSFormControls.spaceInset))
minWidthConstraint = containerView.widthAnchor.constraint(greaterThanOrEqualToConstant: containerSize.width) minWidthConstraint = containerView.widthAnchor.constraint(greaterThanOrEqualToConstant: containerSize.width)
minWidthConstraint?.isActive = true minWidthConstraint?.isActive = true
controlContainerView.addSubview(textView) controlContainerView.addSubview(textView)
@ -117,10 +121,12 @@ open class TextArea: EntryFieldBase {
.pinTrailingLessThanOrEqualTo(nil, 0, .defaultHigh) .pinTrailingLessThanOrEqualTo(nil, 0, .defaultHigh)
.pinBottom(0, .defaultHigh) .pinBottom(0, .defaultHigh)
textView.isScrollEnabled = true textView.isScrollEnabled = true
textView.autocorrectionType = .no
textViewHeightConstraint = textView.heightAnchor.constraint(greaterThanOrEqualToConstant: containerSize.height) textViewHeightConstraint = textView.heightAnchor.constraint(greaterThanOrEqualToConstant: containerSize.height)
textViewHeightConstraint?.isActive = true textViewHeightConstraint?.isActive = true
backgroundColorConfiguration.setSurfaceColors(VDSColor.feedbackSuccessBackgroundOnlight, VDSColor.feedbackSuccessBackgroundOndark, forState: .success) backgroundColorConfiguration.setSurfaceColors(VDSColor.feedbackSuccessBackgroundOnlight, VDSColor.feedbackSuccessBackgroundOndark, forState: .success)
borderColorConfiguration.setSurfaceColors(VDSColor.feedbackSuccessOnlight, VDSColor.feedbackSuccessOndark, forState: .success) borderColorConfiguration.setSurfaceColors(VDSColor.feedbackSuccessOnlight, VDSColor.feedbackSuccessOndark, forState: .success)
borderColorConfiguration.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .focused)
textView.delegate = self textView.delegate = self
} }
@ -182,13 +188,24 @@ open class TextArea: EntryFieldBase {
return bottomView return bottomView
} }
/// Used to update any Accessibility properties.
open override func updateAccessibility() {
super.updateAccessibility()
if showError {
setAccessibilityLabel(for: [titleLabel, textView, errorLabel, helperLabel])
} else {
setAccessibilityLabel(for: [titleLabel, textView, helperLabel])
}
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Private Methods // MARK: - Private Methods
//-------------------------------------------------- //--------------------------------------------------
private func getCharacterCounterText() -> String { private func getCharacterCounterText() -> String {
let count = textView.text.count let count = textView.text.count
let countStr = (count > maxLength ?? 0) ? ("-" + "\(count-(maxLength ?? 0))") : "\(count)" let countStr = (count > maxLength ?? 0) ? ("-" + "\(count-(maxLength ?? 0))") : "\(count)"
if count > maxLength ?? 0 { if ((maxLength ?? 0) > 0) {
if (count > (maxLength ?? 0)) {
showError = true showError = true
errorText = "You have exceeded the character limit." errorText = "You have exceeded the character limit."
return countStr return countStr
@ -197,11 +214,13 @@ open class TextArea: EntryFieldBase {
errorText = "" errorText = ""
return ("\(countStr)" + "/" + "\(maxLength ?? 0)") return ("\(countStr)" + "/" + "\(maxLength ?? 0)")
} }
} else {
return ""
}
} }
open func highlightCharacterOverflow() { open func highlightCharacterOverflow() {
let count = textView.text.count let count = textView.text.count
print("count: \(count), maxLength: \(maxLength ?? 0)")
guard let text = textView.attributedText?.mutableCopy() as? NSMutableAttributedString else { return } guard let text = textView.attributedText?.mutableCopy() as? NSMutableAttributedString else { return }
text.addAttribute(NSAttributedString.Key.backgroundColor, value: highlightBackgroundColor.getColor(self), range: NSRange(location:(maxLength ?? 0 ), length: (count - (maxLength ?? 0)))) text.addAttribute(NSAttributedString.Key.backgroundColor, value: highlightBackgroundColor.getColor(self), range: NSRange(location:(maxLength ?? 0 ), length: (count - (maxLength ?? 0))))
text.addAttribute(NSAttributedString.Key.foregroundColor, value: highlightTextColor.getColor(self), range: NSRange(location:(maxLength ?? 0 ), length: (count - (maxLength ?? 0)))) text.addAttribute(NSAttributedString.Key.foregroundColor, value: highlightTextColor.getColor(self), range: NSRange(location:(maxLength ?? 0 ), length: (count - (maxLength ?? 0))))