From 208298d00dc7a27b8541a2111438f492d46e8402 Mon Sep 17 00:00:00 2001 From: sam marshall Date: Thu, 1 Feb 2024 15:49:28 +0000 Subject: [PATCH] MDL-80805 core_form: Accessibility - add aria-required to form fields Most types of form field will now include aria-required="true" if the field is marked as required. This causes assistive technology to inform users that the field is required. Before this change, in some cases (e.g. screen reader users tabbing through fields) users were not informed that a field is required. --- lib/amd/build/form-autocomplete.min.js | 2 +- lib/amd/build/form-autocomplete.min.js.map | 2 +- lib/amd/src/form-autocomplete.js | 1 + lib/form/templates/element-advcheckbox-inline.mustache | 3 +++ lib/form/templates/element-advcheckbox.mustache | 3 +++ lib/form/templates/element-autocomplete-inline.mustache | 3 +++ lib/form/templates/element-autocomplete.mustache | 3 +++ lib/form/templates/element-checkbox-inline.mustache | 3 +++ lib/form/templates/element-checkbox.mustache | 3 +++ lib/form/templates/element-password-inline.mustache | 6 +++++- lib/form/templates/element-password.mustache | 6 +++++- lib/form/templates/element-passwordunmask.mustache | 3 +++ lib/form/templates/element-radio.mustache | 3 ++- lib/form/templates/element-select-inline.mustache | 3 +++ lib/form/templates/element-select.mustache | 3 +++ lib/form/templates/element-selectgroups-inline.mustache | 3 +++ lib/form/templates/element-selectgroups.mustache | 3 +++ lib/form/templates/element-selectwithlink.mustache | 3 +++ lib/form/templates/element-tags-inline.mustache | 3 +++ lib/form/templates/element-tags.mustache | 3 +++ lib/form/templates/element-text-inline.mustache | 3 +++ lib/form/templates/element-text.mustache | 3 +++ lib/form/templates/element-textarea.mustache | 3 +++ lib/form/templates/element-url.mustache | 3 +++ lib/templates/form_autocomplete_selection.mustache | 1 + 25 files changed, 70 insertions(+), 5 deletions(-) diff --git a/lib/amd/build/form-autocomplete.min.js b/lib/amd/build/form-autocomplete.min.js index faca2e0cd08..5629361ba67 100644 --- a/lib/amd/build/form-autocomplete.min.js +++ b/lib/amd/build/form-autocomplete.min.js @@ -6,6 +6,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since 3.0 */ -define("core/form-autocomplete",["jquery","core/log","core/str","core/templates","core/notification","core/loadingicon","core/aria","core_form/changechecker"],(function($,log,str,templates,notification,LoadingIcon,Aria,FormChangeChecker){var KEYS_DOWN=40,KEYS_ENTER=13,KEYS_SPACE=32,KEYS_ESCAPE=27,KEYS_COMMA=44,KEYS_UP=38,KEYS_LEFT=37,KEYS_RIGHT=39,uniqueId=Date.now(),activateSelection=function(index,state){var selectionElement=$(document.getElementById(state.selectionId)),length=selectionElement.children("[aria-selected=true]").length;for(index%=length;index<0;)index+=length;var element=$(selectionElement.children("[aria-selected=true]").get(index)),itemId=state.selectionId+"-"+index;return selectionElement.children().attr("data-active-selection",null).attr("id",""),element.attr("data-active-selection",!0).attr("id",itemId),selectionElement.attr("aria-activedescendant",itemId),selectionElement.attr("data-active-value",element.attr("data-value")),$.Deferred().resolve()},updateActiveSelectionFromState=function(state){var activeElement=function(state){var _selectionRegion$attr,selectionRegion=$(document.getElementById(state.selectionId)),activeId=selectionRegion.attr("aria-activedescendant");if(activeId){var activeElement=$(document.getElementById(activeId));if(activeElement.length)return activeElement}var activeValue=null===(_selectionRegion$attr=selectionRegion.attr("data-active-value"))||void 0===_selectionRegion$attr?void 0:_selectionRegion$attr.replace(/"/g,'\\"');return selectionRegion.find('[data-value="'+activeValue+'"]')}(state),activeValue=activeElement.attr("data-value"),selectionRegion=$(document.getElementById(state.selectionId));if(activeValue){var activeIndex=selectionRegion.find("[aria-selected=true]").index(activeElement);if(-1!==activeIndex)return void activateSelection(activeIndex,state)}activateSelection(0,state)},updateSelectionList=function(options,state,originalSelect){var pendingKey="form-autocomplete-updateSelectionList-"+state.inputId;M.util.js_pending(pendingKey);var items=[],newSelection=$(document.getElementById(state.selectionId));if(originalSelect.children("option").each((function(index,ele){var label;$(ele).prop("selected")&&(""!==(label=$(ele).data("html")?$(ele).data("html"):$(ele).html())&&items.push({label:label,value:$(ele).attr("value")}))})),!hasItemListChanged(state,items))return M.util.js_complete(pendingKey),Promise.resolve();state.items=items;var context=$.extend(options,state);return templates.render(options.templates.items,context).then((function(html,js){templates.replaceNodeContents(newSelection,html,js),updateActiveSelectionFromState(state)})).then((function(){return M.util.js_complete(pendingKey)})).catch(notification.exception)},hasItemListChanged=function(state,items){return state.items.length!==items.length||state.items.filter((item=>-1===items.indexOf(item))).length>0},notifyChange=function(originalSelect){FormChangeChecker.markFormChangedFromNode(originalSelect[0]),originalSelect[0].dispatchEvent(new Event("change"))},deselectItem=function(options,state,item,originalSelect){var selectedItemValue=$(item).attr("data-value");return void 0!==originalSelect.find("option").first().attr("value")&&originalSelect.prepend($("