Skip to content

Commit

Permalink
Fix: Removed select on focus behaviour allowed space and enter for se…
Browse files Browse the repository at this point in the history
…lection (#230)
  • Loading branch information
oliverfoster authored Feb 4, 2025
1 parent 13ca7d2 commit 5e6284f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
17 changes: 9 additions & 8 deletions js/McqView.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import logging from 'core/js/logging';
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.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);
Expand All @@ -18,18 +23,14 @@ class McqView extends QuestionView {
this.setReadyStatus();
}

onKeyPress(event) {
if (event.which !== 13) return;
// <ENTER> keypress
onKeyDown(event) {
if (!['Enter', ' '].includes(event.key)) return;
event.preventDefault();
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);
Expand Down
4 changes: 2 additions & 2 deletions templates/mcq.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function Mcq(props) {
body,
instruction,
ariaQuestion,
onKeyPress,
onKeyDown,
onItemSelect,
onItemFocus,
onItemBlur
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 5e6284f

Please sign in to comment.