Skip to content

Commit

Permalink
MDL-68167 lib: Fix label for autocomplete selection/suggestion box
Browse files Browse the repository at this point in the history
The content of the autocomplete selection div is purged by javascript
so we have to move its label outside of it. aria-labeledby is the way
to go.

Each time the suggestion box is expanded, autocomplete js renders the
autocomplete suggestions template. So the label cannot be outside the
suggestions ul.
  • Loading branch information
rezaies committed Oct 30, 2020
1 parent ceda246 commit b6d733d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions lang/en/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
$string['showless'] = 'Show less...';
$string['showmore'] = 'Show more...';
$string['somefieldsrequired'] = 'There are required fields in this form marked {$a}.';
$string['suggestions'] = 'Suggestions';
$string['time'] = 'Time';
$string['timeunit'] = 'Time unit';
$string['timing'] = 'Timing';
Expand Down
3 changes: 2 additions & 1 deletion lib/templates/form_autocomplete_selection.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@
{ "label": "Another item label with <strong>tags</strong>", "value": "4" }
], "noSelectionString": "No selection" }
}}
<span class="sr-only" id="{{selectionId}}-label">{{#str}}selecteditems, form{{/str}}</span>
<div{{!
}} class="form-autocomplete-selection w-100 {{#multiple}}form-autocomplete-multiple{{/multiple}}"{{!
}} id="{{selectionId}}"{{!
}} aria-labelledby="{{selectionId}}-label"{{!
}} role="listbox"{{!
}} aria-atomic="true"{{!
}} {{#multiple}}tabindex="0" aria-multiselectable="true"{{/multiple}}>
<span class="accesshide">{{#str}}selecteditems, form{{/str}}</span>
{{> core/form_autocomplete_selection_items }}
</div>
2 changes: 1 addition & 1 deletion lib/templates/form_autocomplete_suggestions.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
{ "label": "Another item label with <strong>tags</strong>", "value": "4" }
]}
}}
<ul class="form-autocomplete-suggestions" id="{{suggestionsId}}" role="listbox" aria-hidden="true" tabindex="-1">
<ul class="form-autocomplete-suggestions" id="{{suggestionsId}}" role="listbox" aria-label="{{#str}}suggestions, form{{/str}}" aria-hidden="true" tabindex="-1">
{{#options}}
<li role="option" data-value="{{value}}">{{{label}}}</li>
{{/options}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@
{ "label": "Another item label with <strong>tags</strong>", "value": "4" }
], "noSelectionString": "No selection" }
}}
<span class="sr-only" id="{{selectionId}}-label">{{#str}}selecteditems, form{{/str}}</span>
<div{{!
}} class="form-autocomplete-selection d-inline-block my-0{{#multiple}} form-autocomplete-multiple h5{{/multiple}}"{{!
}} id="{{selectionId}}"{{!
}} aria-labelledby="{{selectionId}}-label"{{!
}} role="listbox"{{!
}} aria-atomic="true"{{!
}}{{#multiple}} tabindex="0" aria-multiselectable="true"{{/multiple}}{{!
}}>
<span class="accesshide">{{#str}}selecteditems, form{{/str}}</span>
{{> core/form_autocomplete_selection_items }}
</div>

0 comments on commit b6d733d

Please sign in to comment.