From bc423ae26c35006b78e172a0a287a6affe3193b8 Mon Sep 17 00:00:00 2001 From: systemblueteam <252834015+systemblueteam@users.noreply.github.com> Date: Sat, 28 Mar 2026 16:23:24 -0400 Subject: [PATCH] feat: add VoiceOver accessibility labels to keyboard keys --- Sources/Keyboard/KeyboardKey.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Sources/Keyboard/KeyboardKey.swift b/Sources/Keyboard/KeyboardKey.swift index c9bdeca..c692543 100644 --- a/Sources/Keyboard/KeyboardKey.swift +++ b/Sources/Keyboard/KeyboardKey.swift @@ -53,6 +53,21 @@ public struct KeyboardKey: View { var text: String var isActivatedExternally: Bool + /// Accessibility label that expands symbols to spoken words (e.g. "C 4", "F sharp 3") + var accessibilityNoteLabel: String { + let note = pitch.note(in: .C) + let letter = note.noteClass.letter.description + let octave = note.octave + switch note.accidental { + case .sharp: + return "\(letter) sharp \(octave)" + case .flat: + return "\(letter) flat \(octave)" + default: + return "\(letter) \(octave)" + } + } + var keyColor: Color { if isActivatedExternally || isActivated { return pressedColor @@ -121,6 +136,10 @@ public struct KeyboardKey: View { .foregroundColor(textColor) .padding(relativeFontSize(in: proxy.size) / 3.0) } + .accessibilityElement(children: .ignore) + .accessibilityLabel(accessibilityNoteLabel) + .accessibilityAddTraits(.isButton) + .accessibilityValue(isActivated || isActivatedExternally ? "pressed" : "not pressed") } } }