Skip to content

Commit

Permalink
Add method to refresh a11y labels.
Browse files Browse the repository at this point in the history
  • Loading branch information
twstokes committed Mar 20, 2022
1 parent d631556 commit faed559
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions WordPress/Classes/ViewRelated/Menus/MenuItemView.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)refresh;

/**
Refresh the accessibility labels.
*/
- (void)refreshAccessibilityLabels;

/**
The detectedable region of the view for allowing ordering.
*/
Expand Down
15 changes: 15 additions & 0 deletions WordPress/Classes/ViewRelated/Menus/MenuItemView.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ - (void)refresh
{
self.iconView.image = [MenuItem iconImageForItemType:self.item.type];
self.textLabel.text = self.item.name;
[self refreshAccessibilityLabels];
}

- (void)refreshAccessibilityLabels
{
NSString *levelString;
if (self.item.parent) {
levelString = NSLocalizedString(@"Child of %@", @"Screen reader text expressing the menu item is a child of another menu item. Argument is a name for another menu item.");
} else {
levelString = NSLocalizedString(@"Top level", @"Screen reader text expressing the menu item is at the top level.");
}
self.textLabel.accessibilityLabel = [NSString stringWithFormat:@"%@. %@.", self.textLabel.text, levelString];

NSString *labelString = NSLocalizedString(@"Move %@", @"Screen reader text for button that will move the menu item. Argument is menu item's name.");
self.orderingButton.accessibilityLabel = [NSString stringWithFormat:labelString, self.item.name];
}

- (CGRect)orderingToggleRect
Expand Down

0 comments on commit faed559

Please sign in to comment.