From 684424a6e69ccf23375392ab986d4aa46ab48c08 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 4 Feb 2014 11:55:14 +0800 Subject: [PATCH] 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. --- lib/form/yui/shortforms/shortforms.js | 14 ++++++++++++++ lib/formslib.php | 4 +--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/form/yui/shortforms/shortforms.js b/lib/form/yui/shortforms/shortforms.js index 6da2007d12d..112bc69819a 100644 --- a/lib/form/yui/shortforms/shortforms.js +++ b/lib/form/yui/shortforms/shortforms.js @@ -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) { diff --git a/lib/formslib.php b/lib/formslib.php index 5072b5fcb6a..f75a75ca517 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -2549,7 +2549,7 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{ "\n\t\t{header}\n\t\t
\n\t\t"; /** @var string Template used when opening a fieldset */ - var $_openFieldsetTemplate = "\n\t
"; + var $_openFieldsetTemplate = "\n\t
"; /** @var string Template used when closing a fieldset */ var $_closeFieldsetTemplate = "\n\t\t
"; @@ -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++;