Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion less/slider.less
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,12 @@
cursor: pointer;

.is-disabled & {
cursor: default;
}

.show-correct-answer.is-incorrect & {
box-shadow: none;
background-color: transparent;
cursor: default;
}
}

Expand Down
23 changes: 16 additions & 7 deletions templates/slider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,28 @@ export default function Slider (props) {

const sliderNumberSelectionRef = useRef(0);

const correctAnswers = getCorrectAnswers();

const getCorrectRangeMidpoint = () => {
const answers = getCorrectAnswers();
return answers[Math.floor(answers.length / 2)];
return correctAnswers[Math.floor(correctAnswers.length / 2)];
};

const calculatePercentFromIndex = (index) => {
return index / (_items.length - 1) * 100;
};

const isModelRangeShown = _isCorrectAnswerShown ||
(_isInteractionComplete && _isCorrect && _canShowModelAnswer && correctAnswers.length > 1);

const selectedValue = _isCorrectAnswerShown ? getCorrectRangeMidpoint() : (_selectedItem?.value ?? _scaleStart);
const selectedIndex = getIndexFromValue(selectedValue);
const selectedWidth = calculatePercentFromIndex(selectedIndex);

const rangeBottomWidth = correctAnswers.length ? calculatePercentFromIndex(getIndexFromValue(correctAnswers[0])) : 0;
const rangeTopWidth = correctAnswers.length ? calculatePercentFromIndex(getIndexFromValue(correctAnswers[correctAnswers.length - 1])) : 0;
const fillLeft = _isCorrectAnswerShown ? rangeBottomWidth : 0;
const fillWidth = _isCorrectAnswerShown ? rangeTopWidth - rangeBottomWidth : selectedWidth;

const ariaLabels = Adapt.course.get('_globals')._accessibility._ariaLabels;

return (
Expand All @@ -66,8 +75,8 @@ export default function Slider (props) {
scaleStepSuffix && 'has-scale-step-suffix',
!_isEnabled && 'is-disabled',
_isInteractionComplete && 'is-complete is-submitted',
_isInteractionComplete && !_canShowCorrectness && !_isCorrectAnswerShown && 'show-user-answer',
_isInteractionComplete && _canShowModelAnswer && _isCorrectAnswerShown && 'show-correct-answer',
_isInteractionComplete && !_canShowCorrectness && !isModelRangeShown && 'show-user-answer',
_isInteractionComplete && _canShowModelAnswer && isModelRangeShown && 'show-correct-answer',
_isInteractionComplete && _canShowCorrectness && 'show-correctness',
_shouldShowMarking && _isCorrect && 'is-correct',
_shouldShowMarking && !_isCorrect && 'is-incorrect'
Expand Down Expand Up @@ -134,8 +143,8 @@ export default function Slider (props) {

{/* annotate the correct answer range */}
<div className="slider__number-model-range js-slider-model-range">
{_isCorrectAnswerShown &&
getCorrectAnswers().map(correctAnswer => {
{isModelRangeShown &&
correctAnswers.map(correctAnswer => {
return (
<div
className="slider__number-model-answer"
Expand Down Expand Up @@ -224,7 +233,7 @@ export default function Slider (props) {
])}
>
<div className="slider__item-input-track">
<div className="slider__item-input-fill" style={{ width: `${selectedWidth}%` }} />
<div className="slider__item-input-fill" style={{ left: `${fillLeft}%`, width: `${fillWidth}%` }} />
</div>

<input className='slider__item-input js-slider-item-input'
Expand Down