Skip to content

Commit

Permalink
improving accessibility activation of labels containing a single link (
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyalPineapple committed Apr 18, 2024
1 parent cd17bd6 commit 04822e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions BlueprintUICommonControls/Sources/AttributedLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,20 @@ extension AttributedLabel {
attributedText = mutableString
}

override func accessibilityActivate() -> Bool {
/// No links: Not interactive, no effect.
guard links.isEmpty == false else {
return false
}
/// Exactly one link: Activate the link.
if links.count == 1, let url = links.first?.url {
urlHandler?.onTap(url: url)
return true
}
/// More than one link: Ambiguous selection, no effect, Select links using the rotor..
return false
}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard links.isEmpty == false, let first = touches.first else {
return super.touchesBegan(touches, with: event)
Expand Down Expand Up @@ -614,6 +628,7 @@ extension AttributedLabel {
self.link = link
super.init(accessibilityContainer: container)
accessibilityLabel = label
accessibilityTraits = [.link]
}

override var accessibilityFrameInContainerSpace: CGRect {
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed

### Changed
- `AttributedLabel` now activates a single contained link when activated by accessible technologies.
- `AccessibilityElement.CustomContent.Importance.Regular` renamed to `Default`.

### Deprecated
Expand Down

0 comments on commit 04822e7

Please sign in to comment.