Skip to content

Commit

Permalink
[ButtonBar] Fall back to accessibilityLabel for UILargeContentView wh…
Browse files Browse the repository at this point in the history
…en there is an image and no title.

PiperOrigin-RevId: 327013666
  • Loading branch information
yarneo authored and material-automation committed Aug 17, 2020
1 parent 453eaa8 commit ae3fc08
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion components/ButtonBar/src/private/MDCButtonBarButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ - (NSString *)largeContentTitle {
return _largeContentTitle;
}

return [self titleForState:UIControlStateNormal];
NSString *title = [self titleForState:UIControlStateNormal];
if (!title && self.largeContentImage) {
return self.accessibilityLabel;
}

return title;
}

- (UIImage *)largeContentImage {
Expand Down
20 changes: 20 additions & 0 deletions components/ButtonBar/tests/unit/MDCButtonBarTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,26 @@ - (void)testSettingLargeContentImageOnBarButtonSetsItOnButtonBarView {
}
}

- (void)testSettingImageWihNoTitleFallbacksToAccessibilityLabel {
if (@available(iOS 13.0, *)) {
// Given
UIImage *image = [[UIImage alloc] init];
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:image
style:UIBarButtonItemStylePlain
target:nil
action:nil];
item.accessibilityLabel = @"foo";
self.buttonBar.items = @[ item ];

// When
NSArray<UIView *> *itemViews = [self.buttonBar viewsForItems:self.buttonBar.items];
NSString *largeContentTitle = itemViews.firstObject.largeContentTitle;

// Then
XCTAssertEqualObjects(largeContentTitle, item.accessibilityLabel);
}
}

- (void)testSettingLargeContentSizeImageInsetsOnBarButtonSetsItOnButtonBarView {
if (@available(iOS 13.0, *)) {
// Given
Expand Down

0 comments on commit ae3fc08

Please sign in to comment.