Skip to content

Add a11y labels to the send button #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions MessageViewController/MessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ public final class MessageView: UIView, MessageTextViewListener {
get { return textView.textContainerInset }
}

public func setButton(icon: UIImage?, for state: UIControlState, position: ButtonPosition) {
/// - Parameter accessibilityLabel: A custom `accessibilityLabel` to set on the button.
/// If none is supplied, it will default to the icon's `accessibilityLabel`.
public func setButton(icon: UIImage?, for state: UIControlState, position: ButtonPosition, accessibilityLabel: String? = nil) {
let button: UIButton
switch position {
case .left:
Expand All @@ -126,10 +128,13 @@ public final class MessageView: UIView, MessageTextViewListener {
button = rightButton
}
button.setImage(icon, for: state)
button.accessibilityLabel = accessibilityLabel ?? icon?.accessibilityIdentifier
buttonLayoutDidChange(button: button)
}

public func setButton(title: String, for state: UIControlState, position: ButtonPosition) {
/// - Parameter accessibilityLabel: A custom `accessibilityLabel` to set on the button.
/// If none is supplied, it will default to the the supplied `title`.
public func setButton(title: String, for state: UIControlState, position: ButtonPosition, accessibilityLabel: String? = nil) {
let button: UIButton
switch position {
case .left:
Expand All @@ -138,6 +143,7 @@ public final class MessageView: UIView, MessageTextViewListener {
button = rightButton
}
button.setTitle(title, for: state)
button.accessibilityLabel = accessibilityLabel ?? title
buttonLayoutDidChange(button: button)
}

Expand Down