Skip to content

Commit

Permalink
[ActionSheet] Allow changing action item accessibility labels. (#5803)
Browse files Browse the repository at this point in the history
i.e.: We need to show the title as "Resume". But the voice over message should be "Résumé" instead of "Rezoom".
  • Loading branch information
lightboys22 authored and codeman7 committed Dec 6, 2018
1 parent 68ea954 commit f60be33
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions components/ActionSheet/src/MDCActionSheetController.m
Expand Up @@ -56,6 +56,7 @@ - (id)copyWithZone:(__unused NSZone *)zone {
image:self.image
handler:self.completionHandler];
action.accessibilityIdentifier = self.accessibilityIdentifier;
action.accessibilityLabel = self.accessibilityLabel;
return action;
}

Expand Down
Expand Up @@ -143,6 +143,7 @@ - (void)commonMDCActionSheetItemViewInit {
- (void)layoutSubviews {
[super layoutSubviews];

self.actionLabel.accessibilityLabel = _itemAction.accessibilityLabel;
self.actionLabel.text = _itemAction.title;
CGFloat leadingConstant;
if (_itemAction.image) {
Expand All @@ -159,6 +160,7 @@ - (void)layoutSubviews {

- (void)setAction:(MDCActionSheetAction *)action {
_itemAction = [action copy];
self.actionLabel.accessibilityLabel = _itemAction.accessibilityLabel;
self.actionLabel.text = _itemAction.title;
self.actionImageView.image = _itemAction.image;
[self setNeedsLayout];
Expand Down
16 changes: 16 additions & 0 deletions components/ActionSheet/tests/unit/MDCActionSheetTableCellTest.m
Expand Up @@ -152,4 +152,20 @@ - (void)testSetActionFont {
}
}

- (void)testSetActionItemAccessibilityLabel {
// Given
MDCActionSheetAction *action = [MDCActionSheetAction actionWithTitle:@"Resume"
image:nil
handler:nil];
action.accessibilityLabel = @"Résumé";

// When
[self.actionSheet addAction:action];
MDCActionSheetItemTableViewCell *cell =
[MDCActionSheetTestHelper getCellFromActionSheet:self.actionSheet atIndex:0];

// Then
XCTAssertEqual(cell.actionLabel.accessibilityLabel, action.accessibilityLabel);
}

@end
3 changes: 3 additions & 0 deletions components/ActionSheet/tests/unit/MDCActionSheetTestHelper.h
Expand Up @@ -35,4 +35,7 @@
+ (NSArray<MDCActionSheetItemTableViewCell *> *)getCellsFromActionSheet:
(MDCActionSheetController *)actionSheet;

+ (MDCActionSheetItemTableViewCell *)getCellFromActionSheet:(MDCActionSheetController *)actionSheet
atIndex:(NSUInteger)index;

@end
13 changes: 13 additions & 0 deletions components/ActionSheet/tests/unit/MDCActionSheetTestHelper.m
Expand Up @@ -64,4 +64,17 @@ + (void)addNumberOfActions:(NSUInteger)actionsCount
return cellsArray;
}

+ (MDCActionSheetItemTableViewCell *)getCellFromActionSheet:(MDCActionSheetController *)actionSheet
atIndex:(NSUInteger)index {
if (index < actionSheet.actions.count) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
UITableView *table = actionSheet.tableView;
UITableViewCell *cell = [table.dataSource tableView:table cellForRowAtIndexPath:indexPath];
if ([cell isKindOfClass:[MDCActionSheetItemTableViewCell class]]) {
return (MDCActionSheetItemTableViewCell *)cell;
}
}
return nil;
}

@end

0 comments on commit f60be33

Please sign in to comment.