From d92bbb74f7cd031a7cd1a60d467d057555dd8e36 Mon Sep 17 00:00:00 2001 From: Urmit Chauhan Date: Fri, 18 Oct 2024 17:04:06 +0530 Subject: [PATCH 1/2] Add Radio buttons are focusable using arrow keys --- .../Views/ACRChoiceSetView.swift | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) 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() From db0d4cb4a806487dc663468f8b3bc9d0c6c92fa0 Mon Sep 17 00:00:00 2001 From: Urmit Chauhan Date: Wed, 23 Oct 2024 14:06:18 +0530 Subject: [PATCH 2/2] fix datepicker stepper issue --- .../macos/AdaptiveCards/AdaptiveCards/Views/ACRDateField.swift | 1 - 1 file changed, 1 deletion(-) 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() {