Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import AdaptiveCards_bridge
import AppKit
import Carbon.HIToolbox

// MARK: ACRChoiceSetView
class ACRChoiceSetView: NSView, InputHandlingViewProtocol {
Expand Down Expand Up @@ -49,6 +50,46 @@ class ACRChoiceSetView: NSView, InputHandlingViewProtocol {
fatalError("init(coder:) has not been implemented")
}

override func keyDown(with event: NSEvent) {
switch Int(event.keyCode) {
case kVK_DownArrow:
focusNextChoice()
return
case kVK_UpArrow:
focusPreviousChoice()
return
default:
break
}
super.keyDown(with: event)
}

private func focusNextChoice() {
if let currentResponder = self.window?.firstResponder as? NSButton {
let arrayViews = stackview.arrangedSubviews
let currIndex = arrayViews.firstIndex { view in
guard let choiceButton = view as? ACRChoiceButton else { return false }
return choiceButton.button == currentResponder
} ?? 0
let nextIndex = (currIndex + 1) % arrayViews.count
let nextResponder = (arrayViews[nextIndex] as? ACRChoiceButton)?.button
self.window?.makeFirstResponder(nextResponder)
}
}

private func focusPreviousChoice() {
if let currentResponder = self.window?.firstResponder as? NSButton {
let arrayViews = stackview.arrangedSubviews
let currIndex = arrayViews.firstIndex { view in
guard let choiceButton = view as? ACRChoiceButton else { return false }
return choiceButton.button == currentResponder
} ?? 1
let prevIndex = (currIndex - 1 + arrayViews.count) % arrayViews.count
let prevResponder = (arrayViews[prevIndex] as? ACRChoiceButton)?.button
self.window?.makeFirstResponder(prevResponder)
}
}

private func setupView() {
addSubview(stackview)
setupChoices()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ class ACRDateField: NSView {
private func setupPopover() {
datePickerCalendar.dateValue = Date()
datePickerTextfield.dateValue = Date()
datePickerCalendar.setAccessibilityRole(.none)
}

private func setupAccessibility() {
Expand Down