Skip to content

Commit

Permalink
Change voiceNotificationText to be NSAttributedString to allow it…
Browse files Browse the repository at this point in the history
… set priority for announcement.

PiperOrigin-RevId: 559904885
  • Loading branch information
Wenyu Zhang authored and material-automation committed Aug 24, 2023
1 parent 481f11f commit af5c56f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
7 changes: 6 additions & 1 deletion components/Snackbar/src/MDCSnackbarMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ extern NSString *__nonnull const MDCSnackbarMessageBoldAttributeName;
*/
@property(nonatomic, copy, nullable) NSString *accessibilityLabel;

/**
An attributed label that can be used to set priority for the accessibility announcement.
*/
@property(nonatomic, copy, nullable) NSAttributedString *attributedAccessibilityLabel;

/**
Redeclaration from UIAccessibility to make clear that this class supports accessibility hints.
*/
Expand All @@ -184,7 +189,7 @@ extern NSString *__nonnull const MDCSnackbarMessageBoldAttributeName;
/**
Text that should be read when the message appears on screen and VoiceOver is enabled.
*/
@property(nonatomic, readonly, nullable) NSString *voiceNotificationText;
@property(nonatomic, readonly, nullable) NSAttributedString *voiceNotificationText;

/**
By setting this property to @c YES, the Ripple component will be used instead of Ink
Expand Down
21 changes: 17 additions & 4 deletions components/Snackbar/src/MDCSnackbarMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,24 @@ - (void)setDuration:(NSTimeInterval)duration {

#pragma mark - A11y

- (NSString *)voiceNotificationText {
if ([self.accessibilityLabel length]) {
return self.accessibilityLabel;
- (void)setAccessibilityLabel:(NSString *)accessibilityLabel {
if (accessibilityLabel == nil) {
self.attributedAccessibilityLabel = nil;
} else {
return self.text;
self.attributedAccessibilityLabel =
[[NSAttributedString alloc] initWithString:[accessibilityLabel copy]];
}
}

- (NSString *)accessibilityLabel {
return [self.attributedAccessibilityLabel string];
}

- (NSAttributedString *)voiceNotificationText {
if (self.attributedAccessibilityLabel) {
return self.attributedAccessibilityLabel;
} else {
return self.attributedText;
}
}

Expand Down

0 comments on commit af5c56f

Please sign in to comment.