Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: a11y combobox attributes (fixes #147) #198

Merged
merged 10 commits into from
Dec 4, 2024
3 changes: 1 addition & 2 deletions templates/matching.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export default function Matching(props) {
const activeOption = _options.find(option => (option._itemIndex === _index) && option._isActive);
const displayItemAsCorrect = (!_isEnabled && _shouldShowMarking && (_isCorrectAnswerShown || activeOption?._shouldBeSelected));
const questionTitleId = `${_id}-matching-item-${_index}__title`;
const questionTextId = `${_id}-matching-item-${_index}__text`;
const hasMultipleCorrectAnswers = _correctAnswers.length > 1;

return (
Expand All @@ -70,7 +69,7 @@ export default function Matching(props) {

<div className="matching-item__select-container js-matching-item-select-container">

<templates.matchingDropDown {...props} _itemIndex={_index} questionTitleId={questionTitleId} questionTextId={questionTextId}/>
<templates.matchingDropDown {...props} _itemIndex={_index} questionTitleId={questionTitleId}/>

<div className="matching-item__select-state">
<div className="matching-item__select-icon matching-item__select-correct-icon" aria-label={_globals._accessibility._ariaLabels.correct}>
Expand Down
11 changes: 7 additions & 4 deletions templates/matchingDropDown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,19 @@ export default function MatchingDropDown(props) {
!_isEnabled && 'is-disabled',
hasActiveOption && 'is-selected'
])}
role="combobox"
aria-haspopup="listbox"
aria-expanded={isOpen}
aria-controls={`${_id}-matching-item-${_itemIndex}__list`}
onMouseDown={onStartInteraction}
onTouchStart={onStartInteraction}
onClick={onButtonClick}
ref={button}
aria-labelledby={props.questionTitleId + ' ' + props.questionTextId}
aria-labelledby={props.questionTitleId}
aria-activedescendant={highlightedOption && `dropdown__item__${_id}__${_itemIndex}__${highlightedOption._index}`}
joe-allen-89 marked this conversation as resolved.
Show resolved Hide resolved
>

<span id={props.questionTextId} className="dropdown__inner js-dropdown-inner" dangerouslySetInnerHTML={{ __html: displayActiveOption?.text }}>
<span className="dropdown__inner js-dropdown-inner" dangerouslySetInnerHTML={{ __html: displayActiveOption?.text }}>
</span>

<span className="dropdown__icon" aria-hidden="true">
Expand All @@ -205,13 +208,13 @@ export default function MatchingDropDown(props) {
left: buttonOffsetLeft,
width: buttonWidth
}}
id={`${_id}-matching-item-${_itemIndex}__list`}
role="listbox"
tabIndex="-1"
onBlur={onListBlur}
ref={list}
disabled={!_isEnabled}
aria-activedescendant={highlightedOption && `dropdown__item__${_id}__${_itemIndex}__${highlightedOption._index}`}
aria-labelledby={`${_id}-matching-item-${_itemIndex}__title`}
aria-labelledby={props.questionTitleId}
kirsty-hames marked this conversation as resolved.
Show resolved Hide resolved
>

{options.map(({
Expand Down