Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Sources/Keyboard/KeyboardKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
}
}
Loading