Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
[attributed-label] Fix duplicate accessibility elements when whole la…
Browse files Browse the repository at this point in the history
…bel is a link (#684)

Previously when the whole label was a link and link ordering was
NILinkOrderingFirst or NILinkOrderingLast, there would be two duplicate
accessibility elements created - one for the link itself and one for the
entire label.  The one for the entire label wasn't clickable, so it was
useless and confusing.
  • Loading branch information
davidsansome authored and jverkoey committed Mar 12, 2019
1 parent b167ffc commit 50779ce
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/attributedlabel/src/NIAttributedLabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -1755,8 +1755,20 @@ - (NSArray *)accessibleElements {
NSArray *allLinks = [[NSArray arrayWithArray:self.detectedlinkLocations]
arrayByAddingObjectsFromArray:self.explicitLinkLocations];

// If the entire label is a single link, then we want to only end up with one accessibility
// element - not one UIAccessibilityTraitLink element for the link and another
// UIAccessibilityTraitNone element for the entire label.
BOOL entireLabelIsOneLink = NO;
if (allLinks.count == 1) {
NSTextCheckingResult *onlyLink = allLinks.firstObject;
NSRange entireLabelRange = NSMakeRange(0, self.mutableAttributedString.length);
if (NSEqualRanges(onlyLink.range, entireLabelRange)) {
entireLabelIsOneLink = YES;
}
}

// TODO(kaikaiz): remove the first condition when shouldSortLinksLast is fully deprecated.
if (_shouldSortLinksLast || (_linkOrdering != NILinkOrderingOriginal)) {
if ((_shouldSortLinksLast || (_linkOrdering != NILinkOrderingOriginal)) && !entireLabelIsOneLink) {
for (NSTextCheckingResult *result in allLinks) {
NSArray *rectsForLink = [self _rectsForRange:result.range];
if (!NIIsArrayWithObjects(rectsForLink)) {
Expand Down

0 comments on commit 50779ce

Please sign in to comment.