Digital ACT191 story ONEAPP-6682 added accessibility, focused border color to container
This commit is contained in:
parent
5b01027554
commit
72ef366eed
@ -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,26 +188,39 @@ 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) {
|
||||||
showError = true
|
if (count > (maxLength ?? 0)) {
|
||||||
errorText = "You have exceeded the character limit."
|
showError = true
|
||||||
return countStr
|
errorText = "You have exceeded the character limit."
|
||||||
|
return countStr
|
||||||
|
} else {
|
||||||
|
showError = false
|
||||||
|
errorText = ""
|
||||||
|
return ("\(countStr)" + "/" + "\(maxLength ?? 0)")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
showError = false
|
return ""
|
||||||
errorText = ""
|
|
||||||
return ("\(countStr)" + "/" + "\(maxLength ?? 0)")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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))))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user