From faed559cbb7e56ccc01f060e413839fc41b7f115 Mon Sep 17 00:00:00 2001 From: "Tanner W. Stokes" Date: Wed, 16 Mar 2022 21:06:38 -0400 Subject: [PATCH] Add method to refresh a11y labels. --- .../Classes/ViewRelated/Menus/MenuItemView.h | 5 +++++ .../Classes/ViewRelated/Menus/MenuItemView.m | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/WordPress/Classes/ViewRelated/Menus/MenuItemView.h b/WordPress/Classes/ViewRelated/Menus/MenuItemView.h index 9ee8661f0fed..cfdf1fe43f66 100644 --- a/WordPress/Classes/ViewRelated/Menus/MenuItemView.h +++ b/WordPress/Classes/ViewRelated/Menus/MenuItemView.h @@ -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. */ diff --git a/WordPress/Classes/ViewRelated/Menus/MenuItemView.m b/WordPress/Classes/ViewRelated/Menus/MenuItemView.m index c73d70eda20d..8c622100c4e3 100644 --- a/WordPress/Classes/ViewRelated/Menus/MenuItemView.m +++ b/WordPress/Classes/ViewRelated/Menus/MenuItemView.m @@ -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