File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -53,6 +53,21 @@ public struct KeyboardKey: View {
5353 var text : String
5454 var isActivatedExternally : Bool
5555
56+ /// Accessibility label that expands symbols to spoken words (e.g. "C 4", "F sharp 3")
57+ var accessibilityNoteLabel : String {
58+ let note = pitch. note ( in: . C)
59+ let letter = note. noteClass. letter. description
60+ let octave = note. octave
61+ switch note. accidental {
62+ case . sharp:
63+ return " \( letter) sharp \( octave) "
64+ case . flat:
65+ return " \( letter) flat \( octave) "
66+ default :
67+ return " \( letter) \( octave) "
68+ }
69+ }
70+
5671 var keyColor : Color {
5772 if isActivatedExternally || isActivated {
5873 return pressedColor
@@ -121,6 +136,10 @@ public struct KeyboardKey: View {
121136 . foregroundColor ( textColor)
122137 . padding ( relativeFontSize ( in: proxy. size) / 3.0 )
123138 }
139+ . accessibilityElement ( children: . ignore)
140+ . accessibilityLabel ( accessibilityNoteLabel)
141+ . accessibilityAddTraits ( . isButton)
142+ . accessibilityValue ( isActivated || isActivatedExternally ? " pressed " : " not pressed " )
124143 }
125144 }
126145}
You can’t perform that action at this time.
0 commit comments