diff --git a/source/macos/AdaptiveCards/AdaptiveCards/Views/ACRChoiceSetView.swift b/source/macos/AdaptiveCards/AdaptiveCards/Views/ACRChoiceSetView.swift index 8d6878ea4f..ada883a9b9 100644 --- a/source/macos/AdaptiveCards/AdaptiveCards/Views/ACRChoiceSetView.swift +++ b/source/macos/AdaptiveCards/AdaptiveCards/Views/ACRChoiceSetView.swift @@ -1,5 +1,6 @@ import AdaptiveCards_bridge import AppKit +import Carbon.HIToolbox // MARK: ACRChoiceSetView class ACRChoiceSetView: NSView, InputHandlingViewProtocol { @@ -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() diff --git a/source/macos/AdaptiveCards/AdaptiveCards/Views/ACRDateField.swift b/source/macos/AdaptiveCards/AdaptiveCards/Views/ACRDateField.swift index 910b17423d..d45d978528 100644 --- a/source/macos/AdaptiveCards/AdaptiveCards/Views/ACRDateField.swift +++ b/source/macos/AdaptiveCards/AdaptiveCards/Views/ACRDateField.swift @@ -192,7 +192,6 @@ class ACRDateField: NSView { private func setupPopover() { datePickerCalendar.dateValue = Date() datePickerTextfield.dateValue = Date() - datePickerCalendar.setAccessibilityRole(.none) } private func setupAccessibility() {