From cb1607ebde2f86125017b65899142f6136d517ae Mon Sep 17 00:00:00 2001 From: Oliver Foster Date: Thu, 16 Jan 2025 10:03:55 +0000 Subject: [PATCH 1/4] Fix: Removed select on focus behaviour, added is-highlighted class --- js/McqView.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/js/McqView.js b/js/McqView.js index 8c8cd5f..f6a7b38 100644 --- a/js/McqView.js +++ b/js/McqView.js @@ -19,17 +19,13 @@ class McqView extends QuestionView { } onKeyPress(event) { - if (event.which !== 13) return; - // keypress + if (![13, 32].includes(event.which)) return; + // or keypress this.onItemSelect(event); } onItemFocus(event) { if (!this.model.isInteractive()) return; - if (this.model.get('_isRadio')) { - this.onItemSelect(event); - return; - } const index = parseInt($(event.currentTarget).data('adapt-index')); const item = this.model.getChildren().findWhere({ _index: index }); item.set('_isHighlighted', true); From 2a8269cdffdaa1b798120a1a9c26c8c9f519b17e Mon Sep 17 00:00:00 2001 From: Oliver Foster Date: Thu, 16 Jan 2025 17:31:10 +0000 Subject: [PATCH 2/4] Update js/McqView.js Co-authored-by: Brad Simpson --- js/McqView.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/js/McqView.js b/js/McqView.js index f6a7b38..e93ba39 100644 --- a/js/McqView.js +++ b/js/McqView.js @@ -19,8 +19,7 @@ class McqView extends QuestionView { } onKeyPress(event) { - if (![13, 32].includes(event.which)) return; - // or keypress + if (!['Enter', ' '].includes(event.key)) return; this.onItemSelect(event); } From de331257fdfd6f2049d81e7088431ab9ec9b25ab Mon Sep 17 00:00:00 2001 From: Oliver Foster Date: Thu, 16 Jan 2025 18:34:56 +0000 Subject: [PATCH 3/4] Update McqView.js --- js/McqView.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/McqView.js b/js/McqView.js index e93ba39..7a3801c 100644 --- a/js/McqView.js +++ b/js/McqView.js @@ -3,7 +3,7 @@ import QuestionView from 'core/js/views/questionView'; class McqView extends QuestionView { initialize(...args) { - this.onKeyPress = this.onKeyPress.bind(this); + this.onKeyDown = this.onKeyDown.bind(this); this.onItemSelect = this.onItemSelect.bind(this); this.onItemFocus = this.onItemFocus.bind(this); this.onItemBlur = this.onItemBlur.bind(this); @@ -18,7 +18,7 @@ class McqView extends QuestionView { this.setReadyStatus(); } - onKeyPress(event) { + onKeyDown(event) { if (!['Enter', ' '].includes(event.key)) return; this.onItemSelect(event); } From d681bf7f821b98ad91cd172a2733810fa43dce55 Mon Sep 17 00:00:00 2001 From: Oliver Foster Date: Thu, 16 Jan 2025 18:40:43 +0000 Subject: [PATCH 4/4] Fix: Deprecated onKeyPress for onKeyDown --- js/McqView.js | 5 +++++ templates/mcq.jsx | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/js/McqView.js b/js/McqView.js index 7a3801c..29a7318 100644 --- a/js/McqView.js +++ b/js/McqView.js @@ -1,9 +1,14 @@ +import logging from 'core/js/logging'; import QuestionView from 'core/js/views/questionView'; class McqView extends QuestionView { initialize(...args) { this.onKeyDown = this.onKeyDown.bind(this); + this.onKeyPress = (...args) => { + logging.deprecated('McqView onKeyPress is deprecated, please change to onKeyDown'); + this.onKeyDown(...args); + }; this.onItemSelect = this.onItemSelect.bind(this); this.onItemFocus = this.onItemFocus.bind(this); this.onItemBlur = this.onItemBlur.bind(this); diff --git a/templates/mcq.jsx b/templates/mcq.jsx index 264825f..98de5e0 100644 --- a/templates/mcq.jsx +++ b/templates/mcq.jsx @@ -20,7 +20,7 @@ export default function Mcq(props) { body, instruction, ariaQuestion, - onKeyPress, + onKeyDown, onItemSelect, onItemFocus, onItemBlur @@ -69,7 +69,7 @@ export default function Mcq(props) { a11y.normalize(altText || text) : `${_shouldBeSelected ? ariaLabels.correct : ariaLabels.incorrect}, ${_isActive ? ariaLabels.selectedAnswer : ariaLabels.unselectedAnswer}. ${a11y.normalize(altText || text)}`} data-adapt-index={_index} - onKeyPress={onKeyPress} + onKeyDown={onKeyDown} onChange={onItemSelect} onFocus={onItemFocus} onBlur={onItemBlur}