Skip to content

Commit

Permalink
Update: alternative item option text added (fixes #209) (#210)
Browse files Browse the repository at this point in the history
* add item altText property

* add altText to schema

* add altText example

* add altText to schema

* update README

* Normalise altText

Co-authored-by: Oliver Foster <[email protected]>

---------

Co-authored-by: Oliver Foster <[email protected]>
  • Loading branch information
kirsty-hames and oliverfoster authored Oct 30, 2023
1 parent 0e76762 commit 3d4f9ba
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ guide the learner’s interaction with the component.

>**text** (string): Text that comprises the multiple choice option.
>**altText** (string): This will be read out by screen readers instead of reading `text`.
Optional for providing alternative text, for example, to specify how a word should be pronounced.

>**\_shouldBeSelected** (boolean): Determines whether the *item* must be selected for the answer to be correct. Value can be `true` or `false`. The value of **\_selectable** can be smaller, match or exceed the total number of **\_items** where **\_shouldBeSelected** is set to `true`.
>**\_isPartlyCorrect** (boolean): Determines whether the *item* when selected marks the question as partly correct. Value can be `true` or `false`. Default is `false`.
Expand Down
1 change: 1 addition & 0 deletions example.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"_items": [
{
"text": "This is option 1 (Correct)",
"altText": "",
"_shouldBeSelected": true,
"_isPartlyCorrect": false
},
Expand Down
9 changes: 9 additions & 0 deletions properties.schema
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@
"help": "This text will display as the answer text",
"translatable": true
},
"altText": {
"type": "string",
"required": false,
"default": "",
"inputType": "Text",
"validators": [],
"help": "This will be read out by screen readers instead of reading 'text'. Optional for providing alternative text, for example, to specify how a word should be pronounced.",
"translatable": true
},
"_shouldBeSelected": {
"type": "boolean",
"required": true,
Expand Down
8 changes: 8 additions & 0 deletions schema/component.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@
"translatable": true
}
},
"altText": {
"type": "string",
"description": "This will be read out by screen readers instead of reading 'text'. Optional for providing alternative text, for example, to specify how a word should be pronounced.",
"default": "",
"_adapt": {
"translatable": true
}
},
"_shouldBeSelected": {
"type": "boolean",
"title": "Mark this option as correct",
Expand Down
6 changes: 3 additions & 3 deletions templates/mcq.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function Mcq(props) {
aria-label={ariaQuestion || null}
>

{props._items.map(({ text, _index, _isActive, _shouldBeSelected, _isHighlighted }, index) =>
{props._items.map(({ text, altText, _index, _isActive, _shouldBeSelected, _isHighlighted }, index) =>

<div
className={classes([
Expand All @@ -61,8 +61,8 @@ export default function Mcq(props) {
disabled={!_isEnabled}
checked={_isActive}
aria-label={!_shouldShowMarking ?
a11y.normalize(text) :
`${_shouldBeSelected ? ariaLabels.correct : ariaLabels.incorrect}, ${_isActive ? ariaLabels.selectedAnswer : ariaLabels.unselectedAnswer}. ${a11y.normalize(text)}`}
a11y.normalize(altText || text) :
`${_shouldBeSelected ? ariaLabels.correct : ariaLabels.incorrect}, ${_isActive ? ariaLabels.selectedAnswer : ariaLabels.unselectedAnswer}. ${a11y.normalize(altText || text)}`}
data-adapt-index={_index}
onKeyPress={onKeyPress}
onChange={onItemSelect}
Expand Down

0 comments on commit 3d4f9ba

Please sign in to comment.