diff --git a/VDS/Components/TextFields/TextArea/TextArea.swift b/VDS/Components/TextFields/TextArea/TextArea.swift index 1ac1900d..01604134 100644 --- a/VDS/Components/TextFields/TextArea/TextArea.swift +++ b/VDS/Components/TextFields/TextArea/TextArea.swift @@ -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. open override func setup() { super.setup() + accessibilityLabel = "TextArea" + isAccessibilityElement = true + + containerStackView.pinToSuperView(.uniform(VDSFormControls.spaceInset)) minWidthConstraint = containerView.widthAnchor.constraint(greaterThanOrEqualToConstant: containerSize.width) minWidthConstraint?.isActive = true controlContainerView.addSubview(textView) @@ -117,10 +121,12 @@ open class TextArea: EntryFieldBase { .pinTrailingLessThanOrEqualTo(nil, 0, .defaultHigh) .pinBottom(0, .defaultHigh) textView.isScrollEnabled = true + textView.autocorrectionType = .no textViewHeightConstraint = textView.heightAnchor.constraint(greaterThanOrEqualToConstant: containerSize.height) textViewHeightConstraint?.isActive = true backgroundColorConfiguration.setSurfaceColors(VDSColor.feedbackSuccessBackgroundOnlight, VDSColor.feedbackSuccessBackgroundOndark, forState: .success) borderColorConfiguration.setSurfaceColors(VDSColor.feedbackSuccessOnlight, VDSColor.feedbackSuccessOndark, forState: .success) + borderColorConfiguration.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .focused) textView.delegate = self } @@ -182,26 +188,39 @@ open class TextArea: EntryFieldBase { 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 //-------------------------------------------------- private func getCharacterCounterText() -> String { let count = textView.text.count let countStr = (count > maxLength ?? 0) ? ("-" + "\(count-(maxLength ?? 0))") : "\(count)" - if count > maxLength ?? 0 { - showError = true - errorText = "You have exceeded the character limit." - return countStr + if ((maxLength ?? 0) > 0) { + if (count > (maxLength ?? 0)) { + showError = true + errorText = "You have exceeded the character limit." + return countStr + } else { + showError = false + errorText = "" + return ("\(countStr)" + "/" + "\(maxLength ?? 0)") + } } else { - showError = false - errorText = "" - return ("\(countStr)" + "/" + "\(maxLength ?? 0)") + return "" } } open func highlightCharacterOverflow() { let count = textView.text.count - print("count: \(count), maxLength: \(maxLength ?? 0)") 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.foregroundColor, value: highlightTextColor.getColor(self), range: NSRange(location:(maxLength ?? 0 ), length: (count - (maxLength ?? 0))))