Skip to content

Commit a73560a

Browse files
authored
New: Added support for _canShowCorrectness (#213)
1 parent 407ecfa commit a73560a

File tree

6 files changed

+86
-4
lines changed

6 files changed

+86
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ guide the learner’s interaction with the component.
5454

5555
**\_canShowModelAnswer** (boolean): Setting this to `false` prevents the [**_showCorrectAnswer** button](https://github.com/adaptlearning/adapt_framework/wiki/Core-Buttons) from being displayed. The default is `true`.
5656

57+
**\_canShowCorrectness** (boolean): Setting this to `true` replaces the associated `_canShowModelAnswer` toggle button and displays correctness directly on the component. The default is `false`.
58+
5759
**\_canShowFeedback** (boolean): Setting this to `false` disables feedback, so it is not shown to the user. The default is `true`.
5860

5961
**\_canShowMarking** (boolean): Setting this to `false` prevents ticks and crosses being displayed on question completion. The default is `true`.

example.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"_shouldDisplayAttempts": false,
1616
"_questionWeight": 1,
1717
"_canShowModelAnswer": true,
18+
"_canShowCorrectness": false,
1819
"_canShowFeedback": true,
1920
"_canShowMarking": true,
2021
"_recordInteraction": true,

less/slider.less

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,40 @@
3939
}
4040
}
4141

42+
// Correctness state
43+
&__state {
44+
position: relative;
45+
min-height: 1.5rem;
46+
// Indent half the width of the range slider handle either side
47+
margin-left: @slider-handle-width / 2;
48+
margin-right: @slider-handle-width / 2;
49+
50+
.dir-rtl & {
51+
.transform(rotateY(180deg));
52+
}
53+
}
54+
55+
&__icon {
56+
display: flex;
57+
justify-content: center;
58+
align-items: center;
59+
position: absolute;
60+
top: 0;
61+
.transform(translateX(-50%));
62+
63+
.dir-rtl & {
64+
.transform(translateX(-50%) rotateY(180deg));
65+
}
66+
}
67+
68+
&__correct-icon .icon {
69+
.icon-tick;
70+
}
71+
72+
&__incorrect-icon .icon {
73+
.icon-cross;
74+
}
75+
4276
// Scale
4377
&__scale-container {
4478
position: relative;

properties.schema

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@
113113
"validators": [],
114114
"help": "Allow the user to view the 'model answer' if they answer the question incorrectly?"
115115
},
116+
"_canShowCorrectness": {
117+
"type": "boolean",
118+
"required": false,
119+
"default": false,
120+
"title": "Display correctness",
121+
"inputType": "Checkbox",
122+
"validators": [],
123+
"help": "If enabled, this replaces the associated 'model answer' toggle button and displays correctness directly on the component."
124+
},
116125
"_canShowFeedback": {
117126
"type": "boolean",
118127
"required": true,

schema/component.schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@
6565
"description": "Allow the user to view the 'model answer' if they answer the question incorrectly",
6666
"default": true
6767
},
68+
"_canShowCorrectness": {
69+
"type": "boolean",
70+
"title": "Enable to display correctness",
71+
"description": "If enabled, this replaces the associated 'model answer' toggle button and displays correctness directly on the component",
72+
"default": false
73+
},
6874
"_canShowFeedback": {
6975
"type": "boolean",
7076
"title": "Enable feedback",

templates/slider.jsx

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Adapt from 'core/js/adapt';
12
import React, { useRef } from 'react';
23
import { classes, templates } from 'core/js/reactHelpers';
34

@@ -6,6 +7,8 @@ export default function Slider (props) {
67
_id,
78
_globals,
89
_shouldShowMarking,
10+
_canShowModelAnswer,
11+
_canShowCorrectness,
912
_isInteractionComplete,
1013
_isCorrectAnswerShown,
1114
_isEnabled,
@@ -49,6 +52,8 @@ export default function Slider (props) {
4952
const selectedIndex = getIndexFromValue(selectedValue);
5053
const selectedWidth = calculatePercentFromIndex(selectedIndex);
5154

55+
const ariaLabels = Adapt.course.get('_globals')._accessibility._ariaLabels;
56+
5257
return (
5358
<div className="component__inner slider__inner">
5459

@@ -58,7 +63,10 @@ export default function Slider (props) {
5863
className={classes([
5964
'component__widget slider__widget',
6065
!_isEnabled && 'is-disabled',
61-
_isInteractionComplete && 'is-complete is-submitted show-user-answer',
66+
_isInteractionComplete && 'is-complete is-submitted',
67+
_isInteractionComplete && !_canShowCorrectness && !_isCorrectAnswerShown && 'show-user-answer',
68+
_isInteractionComplete && _canShowModelAnswer && _isCorrectAnswerShown && 'show-correct-answer',
69+
_isInteractionComplete && _canShowCorrectness && 'show-correctness',
6270
_shouldShowMarking && _isCorrect && 'is-correct',
6371
_shouldShowMarking && !_isCorrect && 'is-incorrect'
6472
])}
@@ -95,17 +103,20 @@ export default function Slider (props) {
95103

96104
{/* annotate the scale */}
97105
{_showScale && _showScaleNumbers &&
98-
_items.map(({ index, value }) => {
106+
_items.map(({ index, value, correct }) => {
99107
return (
100108
<div
101109
key={index}
102110
className="slider__number js-slider-number js-slider-number-click"
103111
data-id={value}
104-
aria-hidden="true"
112+
aria-disabled= {_isInteractionComplete || null}
105113
style={{ left: `${calculatePercentFromIndex(index)}%` }}
106114
onClick={e => onNumberSelected(parseFloat(e.currentTarget.getAttribute('data-id')))}
107115
>
108-
{scaleStepPrefix}{value}{scaleStepSuffix}
116+
{_shouldShowMarking && _isInteractionComplete &&
117+
<span className="aria-label">{`${correct ? ariaLabels.correct : ariaLabels.incorrect}, ${selectedValue === value ? ariaLabels.selectedAnswer : ariaLabels.unselectedAnswer}. ${scaleStepPrefix}${value}${scaleStepSuffix}`}</span>
118+
}
119+
<span aria-hidden="true">{scaleStepPrefix}{value}{scaleStepSuffix}</span>
109120
</div>
110121
);
111122
})
@@ -147,6 +158,25 @@ export default function Slider (props) {
147158
}
148159
</div>
149160

161+
{/* annotate the answer range correctness */}
162+
{_canShowCorrectness &&
163+
<div className="slider__state" aria-hidden="true">
164+
{_items.slice(0).map((item, index) =>
165+
<div
166+
className={classes([
167+
'slider__icon',
168+
_isInteractionComplete && item.correct && 'slider__correct-icon',
169+
_isInteractionComplete && !item.correct && 'slider__incorrect-icon'
170+
])}
171+
style={{ left: `${calculatePercentFromIndex(index)}%` }}
172+
key={item.value}
173+
>
174+
<span className='icon'></span>
175+
</div>
176+
)}
177+
</div>
178+
}
179+
150180
{/* always present start and end notches */}
151181
<div className="slider__scale-container js-slider-scale">
152182
<div className="slider__scale-notch slider__scale-notch-start" />

0 commit comments

Comments
 (0)