MDL-43969 Forms: Adjust ARIA attributes for short forms
The aria-live="polite" attribute is incorrectly added to the fieldset, causing the entire fieldset to be read out on change in some browsers. This is unnecessary. It also does not announce the current state of the fieldset (collaped or open) and should.
This commit is contained in:
+14
@@ -19,8 +19,10 @@ YUI.add('moodle-form-shortforms', function(Y) {
|
||||
|
||||
var SELECTORS = {
|
||||
COLLAPSEEXPAND : '.collapsible-actions .collapseexpand',
|
||||
COLLAPSED: '.collapsed',
|
||||
FIELDSETCOLLAPSIBLE : 'fieldset.collapsible',
|
||||
FIELDSETLEGENDLINK : 'fieldset.collapsible .fheader',
|
||||
FHEADER: '.fheader',
|
||||
LEGENDFTOGGLER : 'legend.ftoggler'
|
||||
},
|
||||
CSS = {
|
||||
@@ -114,13 +116,25 @@ YUI.add('moodle-form-shortforms', function(Y) {
|
||||
headerlink.appendChild(legendelement.get('firstChild'));
|
||||
headerlink.setAttribute('role', 'button');
|
||||
headerlink.setAttribute('aria-controls', fieldset.generateID());
|
||||
if (legendelement.ancestor(SELECTORS.COLLAPSED)) {
|
||||
headerlink.setAttribute('aria-expanded', 'false');
|
||||
} else {
|
||||
headerlink.setAttribute('aria-expanded', 'true');
|
||||
}
|
||||
legendelement.prepend(headerlink);
|
||||
},
|
||||
set_state: function(fieldset, collapsed) {
|
||||
headerlink = fieldset.one(SELECTORS.FHEADER);
|
||||
if (collapsed) {
|
||||
fieldset.addClass(CSS.COLLAPSED);
|
||||
if (headerlink) {
|
||||
headerlink.setAttribute('aria-expanded', 'false');
|
||||
}
|
||||
} else {
|
||||
fieldset.removeClass(CSS.COLLAPSED);
|
||||
if (headerlink) {
|
||||
headerlink.setAttribute('aria-expanded', 'true');
|
||||
}
|
||||
}
|
||||
var statuselement = this.form.one('input[name=mform_isexpanded_'+fieldset.get('id')+']');
|
||||
if (!statuselement) {
|
||||
|
||||
+1
-3
@@ -2549,7 +2549,7 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
|
||||
"\n\t\t<legend class=\"ftoggler\">{header}</legend>\n\t\t<div class=\"fcontainer clearfix\">\n\t\t";
|
||||
|
||||
/** @var string Template used when opening a fieldset */
|
||||
var $_openFieldsetTemplate = "\n\t<fieldset class=\"{classes}\" {id} {aria-live}>";
|
||||
var $_openFieldsetTemplate = "\n\t<fieldset class=\"{classes}\" {id}>";
|
||||
|
||||
/** @var string Template used when closing a fieldset */
|
||||
var $_closeFieldsetTemplate = "\n\t\t</div></fieldset>";
|
||||
@@ -2833,7 +2833,6 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
|
||||
$fieldsetclasses = array('clearfix');
|
||||
if (isset($this->_collapsibleElements[$header->getName()])) {
|
||||
$fieldsetclasses[] = 'collapsible';
|
||||
$arialive = 'aria-live="polite"';
|
||||
if ($this->_collapsibleElements[$header->getName()]) {
|
||||
$fieldsetclasses[] = 'collapsed';
|
||||
}
|
||||
@@ -2845,7 +2844,6 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
|
||||
|
||||
$openFieldsetTemplate = str_replace('{id}', $id, $this->_openFieldsetTemplate);
|
||||
$openFieldsetTemplate = str_replace('{classes}', join(' ', $fieldsetclasses), $openFieldsetTemplate);
|
||||
$openFieldsetTemplate = str_replace('{aria-live}', $arialive, $openFieldsetTemplate);
|
||||
|
||||
$this->_html .= $openFieldsetTemplate . $header_html;
|
||||
$this->_fieldsetsOpen++;
|
||||
|
||||
Reference in New Issue
Block a user