Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP DNR] Support overriding a11y label on AttributedLabel #493

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions BlueprintUICommonControls/Sources/AttributedLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public struct AttributedLabel: Element, Hashable {
/// A set of accessibility traits that should be applied to the label, these will be merged with any existing traits.
public var accessibilityTraits: Set<AccessibilityElement.Trait>?

/// A localized string that is read when the label is selected by the accessibility system. If this value is not provided,
/// the plain text version of the `attributedText` is used.
public var accessibilityLabel: String?

/// A localized string that describes the result of performing an action on the element, when the result is non-obvious.
public var accessibilityHint: String?

Expand Down Expand Up @@ -252,6 +256,7 @@ extension AttributedLabel {
}

isAccessibilityElement = model.isAccessibilityElement
accessibilityLabel = model.accessibilityLabel
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
accessibilityLabel = model.accessibilityLabel
if let label = model.accessibilityLabel {
accessibilityLabel = label
}

Otherwise a nil value in the var would override the default label

accessibilityHint = model.accessibilityHint
updateAccessibilityTraits(with: model)
accessibilityCustomActions = model.accessibilityCustomActions.map { action in
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- `AttributedLabel` now supports overriding `accessibilityLabel`.

### Removed

### Changed
Expand Down